ValueError: The default Firebase app does not exist. Make sure to initialize the SDK by calling initialize_app().
Fixes firebase-admin used before initialize_app() is called. Use when any firebase_admin call raises this ValueError. Not for credential errors.
TL;DR: You used firebaseadmin before initializing it. Call firebaseadmin.initialize_app(cred) once at startup, before any auth/db/storage calls. Order matters.
ValueError: The default Firebase app does not exist. Make sure to initialize the SDK by calling initialize_app().Fix it
- At the top of your entrypoint, before any firebaseadmin usage: import firebaseadmin; from firebaseadmin import credentials; cred = credentials.Certificate('[path-to-key].json'); firebaseadmin.initialize_app(cred). Expected: no error.
- If you already call it, check order: the failing line runs before initialize_app. Move init to the very top. Expected: fixed.
- Verify: python -c "import firebaseadmin; firebaseadmin.initializeapp(); print(firebaseadmin.get_app().name)". Expected: [DEFAULT].
- For tests, initialize once per process; a second initialize_app() without a name raises a duplicate-app error.
When this applies
- Any firebase_admin call raises this exact ValueError.
When it doesn't
- The error is about the certificate or key file: credential problem, different fix.
- You need multiple projects: use initializeapp(cred, name='[name]') and getapp('[name]').
Compatibility
- firebase-admin 4.x/5.x/6.x.
Why it happens
firebase_admin keeps a registry of named apps; the default app must exist before module-level helpers (auth, db) can resolve it. Importing the submodules does not initialize anything.
Edge cases
- In Cloud Functions, initialize at module scope, not inside the handler, to reuse across invocations.
- ApplicationDefault() credential works on GCP without a key file.
Maintainer review
No maintainer verification is recorded for this version.
This records the version a maintainer checked. It does not assert that the version is the latest upstream release.