Firebase says no default app exists when you call a service
Error: No Firebase App '[DEFAULT]' has been created - call initializeApp() firstShort answer
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. Call initializeApp once, early, and pass or share that app. Admin code uses firebase-admin; browser code uses firebase.
Fix it fast
1Find out which cause you have
Find every place a service is first used and check initializeApp runs before it. Search the project.
grep -rn "initializeApp\|getFirestore\|getAuth\|getDatabase" src/2Match what you see, then jump to its fix
- 1
The error is thrown at import time, before your init code.A service is used before initializeApp runsFix - 2
The error mentions the Admin 'default Firebase app does not exist'.Admin SDK server code never initialized the appFix - 3
initializeApp(config, 'other') exists, and services are called without an app argument.You only initialized a named appFix
- 1
What does the error look like?
Error: No Firebase App '[DEFAULT]' has been created - call initializeApp() firstFirebaseAppError: The default Firebase app does not exist. Make sure you call initializeApp() before using any of the Firebase services.
Cause 1 of 3
A service is used before initializeApp runs
1Check
Modules run in import order. A file that calls getFirestore() at top level can run before the file that initializes.
grep -rn "initializeApp(" src/2Fix
Initialize in one module and import services from it. In the web SDK, pass the app to each service.
// firebase.js
import { initializeApp } from 'firebase/app';
import { getFirestore } from 'firebase/firestore';
const app = initializeApp(firebaseConfig);
export const db = getFirestore(app);3Verify
Start the app and confirm the error is gone.
node --env-file=.env server.jsConfirmed by firebase.google.com
Cause 2 of 3
Admin SDK server code never initialized the app
1Check
firebase-admin needs initializeApp with a credential. In Google-hosted environments it can be called with no arguments; elsewhere it needs a service account key.
echo $GOOGLE_APPLICATION_CREDENTIALS2Fix
Initialize once with application default credentials; set the environment variable to the key file path outside the repo.
import { initializeApp, applicationDefault } from 'firebase-admin/app';
initializeApp({ credential: applicationDefault() });3Verify
Call an Admin service such as getAuth() after the init.
node -e "import('firebase-admin/app').then(m=>console.log(m.getApps().length))"Confirmed by firebase.google.com
Cause 3 of 3
You only initialized a named app
1Check
Services without an argument use the default app. A named app is a separate one.
grep -rn "initializeApp(.*," src/2Fix
Pass the named app to the service, or initialize the default app as well.
const other = initializeApp(otherConfig, 'other');
const db = getFirestore(other);3Verify
The service call returns without the default-app error.
node server.jsConfirmed by firebase.google.com
How do I stop it coming back?
- Keep one firebase.js module that initializes and exports every service.
- Never import both firebase and firebase-admin into the same layer of code.
- Keep service account keys out of git and load them through GOOGLE_APPLICATION_CREDENTIALS.
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 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-admin warns that FIREBASE_CONFIG is missing
Warning, FIREBASE_CONFIG environment variable is missing. Initializing firebase-admin will fail
Cloud Functions for Firebase sets FIREBASE_CONFIG for you; a script run with plain node does not have it.
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