Firebase · sdk · fg-0194

The default Firebase app already exists error on every hot reload in Next.js

If you see FirebaseAppError: The default Firebase app already exists. This means you called initializeApp() more than once without providing an app name as the second argument, the cause and the fix for Firebase are below, last verified 2026-10-15.

Verified Oct 2026trust 50/100
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

Related traps

Have your agent know this before it fails

$ /plugin marketplace add getfootgun/footgun
$ /plugin install footgun@footgun