Description
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
});
}