Maaz Zindani

Loading the index…

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

Firebase says no default app exists when you call a service

ErrorError: No Firebase App '[DEFAULT]' has been created - call initializeApp() first

Short 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.

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

Fix it fast

  1. 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/
  2. 2Match what you see, then jump to its fix

    1. 1The error is thrown at import time, before your init code.A service is used before initializeApp runsFix
    2. 2The error mentions the Admin 'default Firebase app does not exist'.Admin SDK server code never initialized the appFix
    3. 3initializeApp(config, 'other') exists, and services are called without an app argument.You only initialized a named appFix

What does the error look like?

  • Error: No Firebase App '[DEFAULT]' has been created - call initializeApp() first
  • FirebaseAppError: 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.js

Confirmed by firebase.google.com

Did this fix it?

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_CREDENTIALS

2Fix

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

Did this fix it?

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.js

Confirmed by firebase.google.com

Did this fix it?

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:

Related fixes

Back 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 fix

Next step

Want this handled for good?

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