Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4072 pages
Node.js, PHP and APIs

firebase-admin warns that FIREBASE_CONFIG is missing

ErrorWarning, FIREBASE_CONFIG environment variable is missing. Initializing firebase-admin will fail

Short answer

Cloud Functions for Firebase sets FIREBASE_CONFIG for you; a script run with plain node does not have it. The variable only carries optional service options, and credentials come from Application Default Credentials. Run through the emulator, or set the variable and GOOGLE_APPLICATION_CREDENTIALS yourself.

  • Applies to firebase-admin 13, Node.js 22, firebase-tools 14
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Fix it fast

  1. 1Find out which cause you have

    Check whether the process that prints the warning has the variable at all. If it is a plain node script, it will not.

    node -e "console.log(process.env.FIREBASE_CONFIG, process.env.GOOGLE_APPLICATION_CREDENTIALS)"
  2. 2Match what you see, then jump to its fix

    1. 1The command above prints undefined for FIREBASE_CONFIGThe code runs outside Cloud Functions or the emulatorFix
    2. 2The script gets past the warning, then fails with a credentials errorNo credentials are available for local developmentFix
    3. 3The variable is defined in functions/.env but is still missing or ignoredYou tried to set FIREBASE_CONFIG in a .env fileFix

What does the error look like?

  • Warning, FIREBASE_CONFIG environment variable is missing. Initializing firebase-admin will fail

Cause 1 of 3

The code runs outside Cloud Functions or the emulator

1Check

The variable is set automatically in the deployed runtime and in the emulator. A seed script, a test run or a server started with node is neither.

firebase emulators:start --only functions

2Fix

Run the code through the emulator, or give the SDK what it needs: initializeApp() with no arguments uses Application Default Credentials, and you can pass a projectId in the options.

const { initializeApp } = require('firebase-admin/app');
initializeApp({ projectId: 'my-project-id' });

3Verify

Run the script again and the warning no longer stops it.

node seed.js

Confirmed by firebase.google.com

Did this fix it?

Cause 2 of 3

No credentials are available for local development

1Check

Outside Google's environments, Application Default Credentials need a service account key file or an end-user login.

echo $GOOGLE_APPLICATION_CREDENTIALS

2Fix

Point GOOGLE_APPLICATION_CREDENTIALS at the service account key, or log in with gcloud. With the gcloud login, Firebase Authentication also needs the project ID, given as an option or as GOOGLE_CLOUD_PROJECT.

export GOOGLE_APPLICATION_CREDENTIALS="/path/to/service-account.json"
# or
gcloud auth application-default login
export GOOGLE_CLOUD_PROJECT=my-project-id

3Verify

Run the script in the same shell session.

node seed.js

Confirmed by firebase.google.com

Did this fix it?

Cause 3 of 3

You tried to set FIREBASE_CONFIG in a .env file

1Check

Keys that start with FIREBASE_ are reserved and cannot be defined in .env files. The runtime sets this one itself.

grep -n '^FIREBASE_' functions/.env*

2Fix

Delete the line. For a local script that needs the options, export the variable in the shell instead: a JSON string starting with a brace, or a path to a JSON file.

export FIREBASE_CONFIG='{"projectId":"my-project-id","storageBucket":"my-project-id.firebasestorage.app"}'

3Verify

Print the variable in the same shell.

node -e "console.log(process.env.FIREBASE_CONFIG)"

Confirmed by firebase.google.com

Did this fix it?

How do I stop it coming back?

  • Call initializeApp() with no arguments inside deployed functions, so the runtime's own values are used.
  • Keep service account keys out of the repository; load the path from the shell environment.
  • Test functions in the emulator, not by running index.js with node.

Sources

How was this page made?

I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.

Which stack is behind this page?

Projects of mine built on the same technologies:

Related fixes

Back end

Firebase says no default app exists when you call a service

FirebaseAppError: The default Firebase app does not exist. Make sure you call initializeApp() before using any of the Firebase services.

A Firebase service was asked for the default app before initializeApp ran in that same module scope, or on a different copy of the package.

3 causes, each with a fix

Next step

Want this handled for good?

I look after servers, apps and releases end to end. Tell me what keeps breaking.