firebase / firebase/firebase-admin-node

firebase admin: Named export 'firestore' not found

Đang mở
#2,414 1 bình luận 0 reaction 0 người được giao Xem trên GitHub
api: firestore needs-triage
Ngôn ngữ chính
TypeScript
Star
1.7k
Fork
419
Merge trung bình
3 ngày 10 giờ
Pull request đã merge (30 ngày)
16

Mô tả

Unsure if this is a Firebase or sveltekit error

### [REQUIRED] Step 2: Describe your environment

* Operating System version: _____Fedora Silverblue 39 [toolbox]
* Firebase SDK version: _____12.0.0
* Firebase Product: Firestore
* Node.js version: _____20.10.0
* NPM version: _____10.2.3
* Framework_____Sveltekit

### [REQUIRED] Step 3: Describe the problem

When navigating to any route that calls firebase receiving this error

Named export 'firestore' not found. The requested module 'firebase-admin' is a CommonJS module, which may not support all module.exports as named exports.
CommonJS modules can always be imported via the default export

import pkg from 'firebase-admin';
const {firestore} = pkg;

at analyzeImportedModDifference (file:///var/home/dg/devs/sveltefire/node_modules/vite/dist/node/chunks/dep-R0I0XnyH.js:50598:19)
at nodeImport (file:///var/home/dg/devs/sveltefire/node_modules/vite/dist/node/chunks/dep-R0I0XnyH.js:50549:9)
at async ssrImport (file:///var/home/dg/devs/sveltefire/node_modules/vite/dist/node/chunks/dep-R0I0XnyH.js:50444:24)
at async eval (/var/home/dg/devs/sveltefire/src/lib/firebase/database.server.js:4:31)
at async instantiateModule (file:///var/home/dg/devs/sveltefire/node_modules/vite/dist/node/chunks/dep-R0I0XnyH.js:50506:9

#### Steps to reproduce:
Has been working perfectly up until yesterday.
The problem began yesterday
This morning I rebuilt using the latest packages, but the problem still persists
Created another toolbox with a fresh install of node (same version as the previous one

What happened? How can we make the problem occur?
This could be a description, log/console output, etc.

#### Relevant Code:
//firebase.server
import admin from 'firebase-admin';
import serviceAccount from '/src/lib/firebase/firebase-secrets.server.json';

if (admin.apps.length === 0) {
admin.initializeApp({
// @ts-ignore
credential: admin.credential.cert(serviceAccount)
});
}

export const db = admin.firestore();
export const auth = admin.auth();
export const storage = admin.storage();
--------------------------------------------------------------------
//firebase.client
import { getAnalytics } from 'firebase/analytics';
import { getApps, initializeApp } from 'firebase/app';
import { getFirestore } from 'firebase/firestore';
import {
PUBLIC_API_KEY,
PUBLIC_AUTH_DOMAIN,
PUBLIC_PROJECT_ID,
PUBLIC_STORAGE_BUCKET,
PUBLIC_MESSAGING_SENDER_ID,
PUBLIC_API_ID,
PUBLIC_MEASUREMENT_ID
} from '$env/static/public';
import { is_client } from 'svelte/internal';

const firebaseConfig = {
apiKey: PUBLIC_API_KEY,
authDomain: PUBLIC_AUTH_DOMAIN,
projectId: PUBLIC_PROJECT_ID,
storageBucket: PUBLIC_STORAGE_BUCKET,
messagingSenderId: PUBLIC_MESSAGING_SENDER_ID,
appId: PUBLIC_API_ID,
measurementId: PUBLIC_MEASUREMENT_ID
};
if (getApps().length === 0) {
const app = initializeApp(firebaseConfig);
if (is_client) {
getAnalytics(app);
}
}
console.log('firebase was initialized');
export const db = getFirestore();
----------------------------------------------------------------------------------
// database.server
//hte first line is casing the error
import { firestore } from 'firebase-admin';
import { db } from '$lib/firebase/firebase.server';
import { saveFileToBucket } from './firestorage.server';
------------------------------------------------------------------------------------
//database.client
mport { setDoc, collection, doc } from 'firebase/firestore';
import { db } from './firebase.client';

/**
* @param {string | undefined} userId
*/
export async function setUser(userId) {
const users = collection(db, 'users');
await setDoc(doc(users, userId), {
user_id: userId
});
}

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Hướng nghiên cứu

Start with src/lib/firebase/database.server.js and the firebase.server and database.server entry points shown in the report, then reproduce the route navigation with the listed Firebase SDK, Node.js, and SvelteKit environment. Compare the firebase-admin import with the Vite SSR error and verify that affected routes load without the named-export failure.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Đánh giá

Công nghệ
javascript, node.js, vite
Lĩnh vực
backend, databases
Loại issue
Lỗi
Độ khó
4/5
Thời gian dự kiến
3-5 ngày
Mức độ hoạt động
Đình trệ
Độ rõ ràng
Cần làm rõ
Mức phù hợp với người mới
25/100

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.