firebase-admin warns that FIREBASE_CONFIG is missing
Warning, FIREBASE_CONFIG environment variable is missing. Initializing firebase-admin will failShort 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.
Fix it fast
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)"2Match what you see, then jump to its fix
- 1
The command above prints undefined for FIREBASE_CONFIGThe code runs outside Cloud Functions or the emulatorFix - 2
The script gets past the warning, then fails with a credentials errorNo credentials are available for local developmentFix - 3
The variable is defined in functions/.env but is still missing or ignoredYou tried to set FIREBASE_CONFIG in a .env fileFix
- 1
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 functions2Fix
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.jsConfirmed by firebase.google.com
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_CREDENTIALS2Fix
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-id3Verify
Run the script in the same shell session.
node seed.jsConfirmed by firebase.google.com
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
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:
- WorkforceA field app, an admin console and a self-hosted Node.js server for push and reconciliation.
- TaxiDexMy own multi-tenant taxi dispatch SaaS: API, dispatcher portal, driver and passenger apps, and the servers underneath.
- SessionBirdAn omnichannel engagement suite in Flutter: campaigns, chatbot, tickets, analytics and live calling.
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 fixBack end
Firebase Cloud Functions respond slowly, especially on the first call
Every function in the project is slow after deploy, even tiny ones
Most slow first calls are cold starts: the runtime starts from scratch, loads your code and runs global-scope work before it can answer.
3 causes, each with a fixBack end
firebase deploy --only functions fails with a generic deploy error
HTTP 429
The generic message hides a specific one.
3 causes, each with a fixBack end
firebase deploy cannot load the .env file in the functions folder
FirebaseError: Failed to load environment variables from .env
The CLI reads .env files from the functions folder at deploy time and rejects ones it cannot use.
3 causes, each with a fixBack end
firebase deploy cannot load your functions: user code failed to load
Functions codebase could not be analyzed successfully. It may have a syntax or runtime error
The Firebase CLI loads your functions code on your machine before it deploys, to learn which functions exist.
4 causes, each with a fixBack end
Firebase Functions fails to load because csv-parse/sync is missing
Cannot find module 'csv-parse'
Firebase installs only what the functions package.json lists under dependencies, and it ignores your local node_modules at deploy.
3 causes, each with a fix