- Symptom
- FirebaseAppError: The default Firebase app already exists. This means you called initializeApp() more than once without providing an app name as the second argument.Appears after editing a file in next dev or across API route invocationsProduction build works, dev server breaks
- Cause
- Next.js re-evaluates modules on hot reload and across route bundles while the Node process keeps the earlier app instance, so initializeApp runs twice for the same default app.
- Fix
- Reuse the existing app with getApps() before calling initializeApp.
- Apply
import { getApps, initializeApp, cert } from 'firebase-admin/app'; export const adminApp = getApps().length ? getApps()[0] : initializeApp({ credential: cert(JSON.parse(process.env.FIREBASE_SERVICE_ACCOUNT)) });- Affected
- firebase-admin initialized at module scope without a getApps() guard, under next dev hot reload or when several route bundles share one Node.js process
- Sources
Last verified 2026-10-15 · Confirmed by 0 builders