Firebase App named '[DEFAULT]' already exists (app/duplicate-app)

倖福魔咒の 提交于 2019-11-29 13:09:58
if (!firebase.apps.length) {
   firebase.initializeApp({});
}

Similar answer here

I had the same issue using firebase, and I discover that I was initializing the firebase twice, example:

function initializeFirebase(){    
 var config = {
    apiKey: "myApiKey",
    authDomain: "myAuthDomain",
    databaseURL: "myDatabaseUrl",
    storageBucket: "myStorageBocket",
    messagingSenderId: "idhere"   
   };   
   //initialize firebase  
   firebase.initializeApp(config);  
}

In my case I was using react, And I was calling initializeFirebase() from two different components, but I've decided to call it from the parent component. And now I'm able to query my database, insert records, remove, etc.

Hope this helps someone

i only glanced at your github repo to see that there is more .js files than suggested in your question. i had 2 separate .js files. both being included on the same html page that were both configuring and initializing the default app when it only needed to be done once for that page i believe. what worked for me was to comment out the second "initializeApp()" and i no longer got that error. try to look for the below in your .js and comment out or delete one of the initializations.

var config = { apiKey: "my api key", authDomain: "something.firebaseapp.com", databaseURL: "https://somesite.firebaseio.com", projectId: "myProjectId", storageBucket: "somesite.appspot.com", messagingSenderId: "someIntegers" }; //firebase.initializeApp(config);

I recently solved this issue in my own code. My issue was caused by accidentally linking my javascript file, which calls initializeApp(), in the head and in the body of my html file. My fix was to delete the duplicate javascript tag in the head of my html file so only one existed in the body.

Scan through your code to make sure you only call initializeApp() once. This includes any js files that might be calling the method or duplicating the js file in your html file.

I have had the same problem

if you are using ES6 modules and you installed firebase by npm you can not put init scrips into index.html

it is duplications of firebase dependancies

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!