danny-avila/LibreChat · critical
Firebase is not initialized
Error message
Firebase is not initialized
What it means
Thrown by deleteFile (Firebase/crud.js) when getFirebaseStorage() returns a falsy value — i.e. Firebase Storage was never initialized in this process. The service is selected by config but its credentials/setup are missing, so any delete attempt is impossible.
Source
Thrown at api/server/services/Files/Firebase/crud.js:27
assertRemoteFileURL,
getRemoteFileFetchMaxBytes,
getRemoteFileFetchTimeoutMs,
assertRemoteFileContentLength,
} = require('@librechat/api');
const { ref, uploadBytes, getDownloadURL, deleteObject } = require('firebase/storage');
const { getBufferMetadata } = require('~/server/utils');
/**
* Deletes a file from Firebase Storage.
* @param {string} directory - The directory name
* @param {string} fileName - The name of the file to delete.
* @returns {Promise<void>} A promise that resolves when the file is deleted.
*/
async function deleteFile(basePath, fileName) {
const storage = getFirebaseStorage();
if (!storage) {
logger.error('Firebase is not initialized. Cannot delete file from Firebase Storage.');
throw new Error('Firebase is not initialized');
}
const storageRef = ref(storage, `${basePath}/${fileName}`);
try {
await deleteObject(storageRef);
logger.debug('File deleted successfully from Firebase Storage');
} catch (error) {
logger.error('Error deleting file from Firebase Storage:', error.message);
throw error;
}
}
/**
* Saves an file from a given URL to Firebase Storage. The function first initializes the Firebase Storage
* reference, then uploads the file to a specified basePath in the Firebase Storage. It handles initialization
* errors and upload errors, logging them to the console. If the upload is successful, the file name is returned.
*View on GitHub (pinned to 5ff282f900)
Solutions
- Verify the Firebase service-account / config env vars are present and valid in this environment.
- Confirm the storage provider selection actually intends Firebase (otherwise switch to local/S3/Azure).
- Ensure Firebase initialization runs at boot before any file route is hit.
- Check logs for the earlier init error that left storage null (this throw is a downstream symptom).
Defensive patterns
Strategy: validation
Validate before calling
// Before any file delete, confirm Firebase is actually initialized
const { getFirebaseStorage } = require('~/server/services/Files/Firebase/initializeFirebase');
if (provider === 'firebase' && !getFirebaseStorage()) {
throw new Error('Firebase storage selected but not initialized — check credentials');
} Try / catch
try {
await firebaseDeleteFile(basePath, fileName);
} catch (err) {
if (/Firebase is not initialized/.test(err.message)) {
return res.status(503).json({ message: 'File storage is not configured' });
}
throw err;
} Prevention
- Confirm Firebase service-account env vars are present and valid at boot.
- Fail fast at startup if the selected storage provider cannot initialize.
- Keep the storage provider selection consistent with the configured credentials.
When it happens
Trigger: The app is configured to use Firebase as the storage provider, but getFirebaseStorage() returned null because Firebase init failed or was never called (missing service account, bad config, init threw silently).
Common situations: FIREBASE_SERVICES or storage credential env vars are missing/incomplete; LIBRECHAT_FILES_DIR or storage provider selection points at Firebase without the matching credentials; a refactor moved init off the eager path; wrong storage provider selected for this environment.
Related errors
- Assistants API key not provided. Please provide it again.
- Failed to fetch URL: ${response.status} ${response.statusTex
- Missing AZURE_AI_SEARCH_SERVICE_ENDPOINT, AZURE_AI_SEARCH_IN
- Missing DALLE_API_KEY environment variable.
- Missing FLUX_API_KEY environment variable.
AI-assisted analysis of danny-avila/LibreChat@5ff282f900 (2026-08-12).
Data as JSON: /api/errors/50d882babc914ef9.
Report an issue: GitHub.