Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Hi I am trying to unit test while developing a simple web with AngularJS + Firebase, but I have a problem defining the spec and trying the test runner

myProject/test/spec/main.js :

describe('Controller: MainCtrl', function() {  var MainCtrl, scope  beforeEach(module('MainApp'));  beforeEach(inject(function ($controller, $rootScope) {     scope = $rootScope.$new();     MainCtrl = $controller('MainCtrl', {         $scope: scope     }) }));  it('should....',function(){     expect(true).toBe(true) }) it('should2....',function(){     expect(false).toBe(false) }) }); 

result:

PhantomJS 2.1.1 (Mac OS X 0.0.0) Controller: MainCtrl should.... FAILED Error: [$injector:modulerr] Failed to instantiate module MainApp due  to: Firebase: Firebase App named '[DEFAULT]' already exists  (app/duplicateapp). 

However, defining the spec once is not a problem. For example:

it('should....',function(){    expect(true).toBe(true) }) 

I do not know why this is the reason I give a hint to me

Here is the project I am developing.

https://github.com/parkwookyun/firebase-angular-board

like image 715
parkwookyun Avatar asked Apr 10 '17 19:04

parkwookyun


2 Answers

if (!firebase.apps.length) {    firebase.initializeApp({}); }else {    firebase.app(); // if already initialized, use that one } 

Similar answer here

like image 118
Isaac Sekamatte Avatar answered Oct 06 '22 00:10

Isaac Sekamatte


I had the same issue using firebase, and I realized 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

like image 39
Erick Garcia Avatar answered Oct 06 '22 01:10

Erick Garcia