Firebase · sdk · fg-0194
The default Firebase app already exists error on every hot reload in Next.js
FirebaseAppError: The default Firebase app already exists. This means you called initializeApp() more than once without providing an app name as the second argument.
Verified 2026-10-15 · Confirmed by 0 builders · Trust 50/100
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)) });Affects: 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
Have your agent know this before it fails
claude mcp add --transport http footgun https://getfootgun.com/api/mcp