[SOLVED] Do I really need to declare initializeApp twice in order to use firebase SDK and AngularFireModule?


#1

Everything is working fine at the moment but I’m not sure why I have to write initializeApp twice at app.module.ts.
If I remove initializeApp statement for firebase SDK from app.module.ts, then I get the following error.

Firebase: No Firebase App ‘[DEFAULT]’ has been cre…- call Firebase App.initializeApp() (app/no-app).

app.module.ts

import { AngularFireModule } from 'angularfire2';
import { AngularFireDatabaseModule, AngularFireDatabase } from 'angularfire2/database';
import { AngularFireAuthModule } from 'angularfire2/auth';
import { environment } from '../environments/environment'

import * as firebase from 'firebase/app';

firebase.initializeApp(environment.firebase);
@NgModule({
  declarations: [
    MyApp
  ],
  imports: [
    BrowserModule,
    FormsModule,
    ReactiveFormsModule,
    HttpModule,
    IonicModule.forRoot(MyApp),
    AngularFireModule.initializeApp(environment.firebase),
    AngularFireAuthModule,
    AngularFireDatabaseModule,
  ],
...
providers: [
    AngularFireDatabase,
    ...
    {provide: ErrorHandler, useClass: IonicErrorHandler}
  ]

auth-service.ts

import { AngularFireDatabase, AngularFireList, AngularFireObject } from 'angularfire2/database';
import * as firebase from 'firebase/app';

constructor(
    private afAuth: AngularFireAuth,
    private afDB: AngularFireDatabase) { }

resetPassword(email: string) {
    return new Promise((resolve, reject) => {
      firebase.auth().sendPasswordResetEmail(email).then(() => {resolve({status: true});
    }).catch(err => reject(err));
    });
  } 

Ionic Info

cli packages: (/usr/local/lib/node_modules)

@ionic/cli-utils  : 1.19.0
ionic (Ionic CLI) : 3.19.0

global packages:

cordova (Cordova CLI) : 7.1.0

local packages:

@ionic/app-scripts : 3.1.2
Cordova Platforms  : none
Ionic Framework    : ionic-angular 3.9.2

#2

I removed the name of the app from AngularFireModule.initializeApp()


#3

Kindly explain what was your solution to this exactly, coz i find myself intitializing twice with the same firebase config for it to work. first with firbase then with the AngularFireModule in imports