-
Notifications
You must be signed in to change notification settings - Fork 356
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Firebase.initializeApp
throwing default Firebase app already exists
errors in Next.js apps.
#2111
Comments
I found a few problems with this issue:
|
I meet the exact same issue. Just use nextjs and it will trigger this issue |
I had the same issue with Next 13, in order to fix it I did this workaround: import { getApps, initializeApp } from "firebase-admin/app";
import { getAuth } from "firebase-admin/auth";
const alreadyCreatedAps = getApps();
const yourFirebaseAdminConfig= {}
const App =
alreadyCreatedAps.length === 0
? initializeApp({yourFirebaseAdminConfig}, "app name")
: alreadyCreatedAps[0]; Describe your environment:
|
Thank you for this clever solution |
thanks for this...Next.js 13 has a lot of issues |
Thanks to @MauricioBorawski 's solution, I was able to remove the error while HMR.
Describe your environment:
|
I'm not sure this solution works, as far as I can tell. It will work on the dev environment, but once deployed Firebase will complain that the app needs to be initialized first. I think that conditional causes problems. By extension, I've had to make code changes to deploy the app. |
@jessejamesrich How did you do for production? i am getting this error after deployment : FirebaseAppError: The default Firebase app does not exist. Make sure you call initializeApp() before using any of the Firebase services. |
On dev I have to use the conditional to check if app exists (!admin.app.length) to make sure admin.initializeApp doesn't run again, but I have to comment out the conditional before deploying as Firebase seems to fail if (I assume) the first process run isn't admin initialization. This is the best I can figure. It works, but I means you have to make changes to the code before deploying and then back again to get dev working. Here's what it looks like.
|
Olá, estou enfrentando o mesmo problema. Estou usando o cron job da Vercel, eu uso o firestore do firebase e a terefa do cron é deletar dados em determinado horário. Nisso eu preciso usar o admin SDK do google cloud para conseguir ter acesso ao firestore e excluir os dados. Porém, em produção quando tento chamar minha função cron job exemplo: https://sitename/api/cron, nada acontece. ja em desenvolvimento funciona perfeitamente. Quem encontrar alguma solução poderia me ajudar? |
Still having this issue? What's your logs for the https://sitename/api/cron call ? Regards |
Describe your environment
"firebase-admin": "^11.5.0"
Firebase.initializeApp
Describe the problem
Using Next.js SSR with Firebase consequently calls methods that call
Firebase.initializeApp
multiple times. This causes the following error to be thrown:This issue is related to #571 (comment), but the resolution is not helpful and the supplied link (https://firebase.google.com/docs/reference/admin/node/admin.app.App.html#name) results in a 404.
Steps to reproduce:
Create a Next.js app using Server Side Rendering (SSR)
Workaround
I found a workaround by first checking if I've already initialized any apps before calling
initializeApp()
again:The text was updated successfully, but these errors were encountered: