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

  1. Verify the Firebase service-account / config env vars are present and valid in this environment.
  2. Confirm the storage provider selection actually intends Firebase (otherwise switch to local/S3/Azure).
  3. Ensure Firebase initialization runs at boot before any file route is hit.
  4. 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

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


AI-assisted analysis of danny-avila/LibreChat@5ff282f900 (2026-08-12). Data as JSON: /api/errors/50d882babc914ef9. Report an issue: GitHub.