{"record":{"id":"50d882babc914ef9","repo":"danny-avila/LibreChat","slug":"firebase-is-not-initialized","errorCode":null,"errorMessage":"Firebase is not initialized","messagePattern":"Firebase is not initialized","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"critical","filePath":"api/server/services/Files/Firebase/crud.js","lineNumber":27,"sourceCode":"  assertRemoteFileURL,\n  getRemoteFileFetchMaxBytes,\n  getRemoteFileFetchTimeoutMs,\n  assertRemoteFileContentLength,\n} = require('@librechat/api');\nconst { ref, uploadBytes, getDownloadURL, deleteObject } = require('firebase/storage');\nconst { getBufferMetadata } = require('~/server/utils');\n\n/**\n * Deletes a file from Firebase Storage.\n * @param {string} directory - The directory name\n * @param {string} fileName - The name of the file to delete.\n * @returns {Promise<void>} A promise that resolves when the file is deleted.\n */\nasync function deleteFile(basePath, fileName) {\n  const storage = getFirebaseStorage();\n  if (!storage) {\n    logger.error('Firebase is not initialized. Cannot delete file from Firebase Storage.');\n    throw new Error('Firebase is not initialized');\n  }\n\n  const storageRef = ref(storage, `${basePath}/${fileName}`);\n\n  try {\n    await deleteObject(storageRef);\n    logger.debug('File deleted successfully from Firebase Storage');\n  } catch (error) {\n    logger.error('Error deleting file from Firebase Storage:', error.message);\n    throw error;\n  }\n}\n\n/**\n * Saves an file from a given URL to Firebase Storage. The function first initializes the Firebase Storage\n * reference, then uploads the file to a specified basePath in the Firebase Storage. It handles initialization\n * errors and upload errors, logging them to the console. If the upload is successful, the file name is returned.\n *","sourceCodeStart":9,"sourceCodeEnd":45,"githubUrl":"https://github.com/danny-avila/LibreChat/blob/5ff282f9006c436e561de1afd39a481bea1ef0d8/api/server/services/Files/Firebase/crud.js#L9-L45","documentation":"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.","triggerScenarios":"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).","commonSituations":"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.","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)."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"// Before any file delete, confirm Firebase is actually initialized\nconst { getFirebaseStorage } = require('~/server/services/Files/Firebase/initializeFirebase');\nif (provider === 'firebase' && !getFirebaseStorage()) {\n  throw new Error('Firebase storage selected but not initialized — check credentials');\n}","typeGuard":null,"tryCatchPattern":"try {\n  await firebaseDeleteFile(basePath, fileName);\n} catch (err) {\n  if (/Firebase is not initialized/.test(err.message)) {\n    return res.status(503).json({ message: 'File storage is not configured' });\n  }\n  throw err;\n}","preventionTips":["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."],"tags":["firebase","storage","config","initialization"],"backgroundTag":null,"analyzedSha":"5ff282f9006c436e561de1afd39a481bea1ef0d8","analyzedAt":"2026-08-12T21:38:08.145Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}