mirror of
https://github.com/danny-avila/LibreChat.git
synced 2026-11-25 17:32:49 +00:00
The `@librechat/api` build migrated to tsdown (rolldown/oxc) in #13595. tsdown externalizes third-party deps and uses strict CJS interop, so a default import of the Firebase v9+ modular SDK — whose CJS entry is `__esModule`-marked with only named exports and no `default` — resolves to `undefined`. `firebase.initializeApp(...)` then throws: TypeError: Cannot read properties of undefined (reading 'initializeApp') crashing startup whenever the Firebase file strategy is configured (`fileStrategy: firebase` or a granular `fileStrategies` entry). Switch to the idiomatic modular named import (`initializeApp`) and use the already-imported `FirebaseApp` type for the return annotation.
42 lines
1.4 KiB
TypeScript
42 lines
1.4 KiB
TypeScript
import { initializeApp } from 'firebase/app';
|
|
import { getStorage } from 'firebase/storage';
|
|
import { logger } from '@librechat/data-schemas';
|
|
import type { FirebaseStorage } from 'firebase/storage';
|
|
import type { FirebaseApp } from 'firebase/app';
|
|
|
|
let firebaseInitCount = 0;
|
|
let firebaseApp: FirebaseApp | null = null;
|
|
|
|
export const initializeFirebase = (): FirebaseApp | null => {
|
|
if (firebaseApp) {
|
|
return firebaseApp;
|
|
}
|
|
|
|
const firebaseConfig = {
|
|
apiKey: process.env.FIREBASE_API_KEY,
|
|
authDomain: process.env.FIREBASE_AUTH_DOMAIN,
|
|
projectId: process.env.FIREBASE_PROJECT_ID,
|
|
storageBucket: process.env.FIREBASE_STORAGE_BUCKET,
|
|
messagingSenderId: process.env.FIREBASE_MESSAGING_SENDER_ID,
|
|
appId: process.env.FIREBASE_APP_ID,
|
|
};
|
|
|
|
if (Object.values(firebaseConfig).some((value) => !value)) {
|
|
if (firebaseInitCount === 0) {
|
|
logger.info(
|
|
'[Optional] Firebase CDN not initialized. To enable, set FIREBASE_API_KEY, FIREBASE_AUTH_DOMAIN, FIREBASE_PROJECT_ID, FIREBASE_STORAGE_BUCKET, FIREBASE_MESSAGING_SENDER_ID, and FIREBASE_APP_ID environment variables.',
|
|
);
|
|
}
|
|
firebaseInitCount++;
|
|
return null;
|
|
}
|
|
|
|
firebaseApp = initializeApp(firebaseConfig);
|
|
logger.info('Firebase CDN initialized');
|
|
return firebaseApp;
|
|
};
|
|
|
|
export const getFirebaseStorage = (): FirebaseStorage | null => {
|
|
const app = initializeFirebase();
|
|
return app ? getStorage(app) : null;
|
|
};
|