I've upgraded to the latest version of @angular/fire recently, and everything worked fine, but now I've migrated away from the pat libraries, and now I'm stuck with this issue. I get this error on the following code:
Firebase: No Firebase App '[DEFAULT]' has been created - call Firebase App.initializeApp()
.
// ...
import {getAuth, provideAuth} from '@angular/fire/auth';
import {getFirestore, provideFirestore} from '@angular/fire/firestore';
import {initializeApp, provideFirebaseApp} from '@angular/fire/app';
// ...
@NgModule({
// ...
providers: [
// ...
provideFirebaseApp(() => initializeApp(window['firebase_config'])),
provideFirestore(() => getFirestore()),
provideAuth(() => getAuth()),
// ...
],
// ...
})
export class ApModule {
// ...
}
Here is the stack trace:
Error: Firebase: No Firebase App '[DEFAULT]' has been created - call Firebase App.initializeApp() (app/no-app).
at new ZoneAwareError (http://localhost:4200/vendor.js:65953:33)
at new FirebaseError (http://localhost:4200/apps_frontend_src_app_app_module_ts.js:166709:5)
at ErrorFactory.create (http://localhost:4200/apps_frontend_src_app_app_module_ts.js:166739:19)
at getApp (http://localhost:4200/apps_frontend_src_app_app_module_ts.js:122971:25)
at getAuth (http://localhost:4200/apps_frontend_src_app_app_module_ts.js:137360:77)
at http://localhost:4200/apps_frontend_src_app_app_module_ts.js:69140:44
at http://localhost:4200/apps_frontend_src_app_app_module_ts.js:69066:57
at ZoneDelegate.invoke (http://localhost:4200/polyfills.js:463:26)
at Zone.run (http://localhost:4200/polyfills.js:225:43)
at NgZone.runOutsideAngular (http://localhost:4200/vendor.js:34688:28)
at runOutsideAngular (http://localhost:4200/apps_frontend_src_app_app_module_ts.js:69066:33)
at http://localhost:4200/apps_frontend_src_app_app_module_ts.js:69140:17
at http://localhost:4200/apps_frontend_src_app_app_module_ts.js:1581:144
at http://localhost:4200/apps_frontend_src_app_app_module_ts.js:68430:47
at ZoneDelegate.invoke (http://localhost:4200/polyfills.js:463:26)
I'm totally confused on why I'm getting this error. Any help is much appreciated!
I've upgraded to the latest version of @angular/fire recently, and everything worked fine, but now I've migrated away from the pat libraries, and now I'm stuck with this issue. I get this error on the following code:
Firebase: No Firebase App '[DEFAULT]' has been created - call Firebase App.initializeApp()
.
// ...
import {getAuth, provideAuth} from '@angular/fire/auth';
import {getFirestore, provideFirestore} from '@angular/fire/firestore';
import {initializeApp, provideFirebaseApp} from '@angular/fire/app';
// ...
@NgModule({
// ...
providers: [
// ...
provideFirebaseApp(() => initializeApp(window['firebase_config'])),
provideFirestore(() => getFirestore()),
provideAuth(() => getAuth()),
// ...
],
// ...
})
export class ApModule {
// ...
}
Here is the stack trace:
Error: Firebase: No Firebase App '[DEFAULT]' has been created - call Firebase App.initializeApp() (app/no-app).
at new ZoneAwareError (http://localhost:4200/vendor.js:65953:33)
at new FirebaseError (http://localhost:4200/apps_frontend_src_app_app_module_ts.js:166709:5)
at ErrorFactory.create (http://localhost:4200/apps_frontend_src_app_app_module_ts.js:166739:19)
at getApp (http://localhost:4200/apps_frontend_src_app_app_module_ts.js:122971:25)
at getAuth (http://localhost:4200/apps_frontend_src_app_app_module_ts.js:137360:77)
at http://localhost:4200/apps_frontend_src_app_app_module_ts.js:69140:44
at http://localhost:4200/apps_frontend_src_app_app_module_ts.js:69066:57
at ZoneDelegate.invoke (http://localhost:4200/polyfills.js:463:26)
at Zone.run (http://localhost:4200/polyfills.js:225:43)
at NgZone.runOutsideAngular (http://localhost:4200/vendor.js:34688:28)
at runOutsideAngular (http://localhost:4200/apps_frontend_src_app_app_module_ts.js:69066:33)
at http://localhost:4200/apps_frontend_src_app_app_module_ts.js:69140:17
at http://localhost:4200/apps_frontend_src_app_app_module_ts.js:1581:144
at http://localhost:4200/apps_frontend_src_app_app_module_ts.js:68430:47
at ZoneDelegate.invoke (http://localhost:4200/polyfills.js:463:26)
I'm totally confused on why I'm getting this error. Any help is much appreciated!
Share Improve this question edited Nov 4, 2021 at 14:00 Frank van Puffelen 601k85 gold badges890 silver badges860 bronze badges Recognized by Google Cloud Collective asked Nov 4, 2021 at 9:14 Bart van den BurgBart van den Burg 2,3645 gold badges28 silver badges47 bronze badges4 Answers
Reset to default 4Apparently the issue was a mismatch in versions between firebase
and @firebase/app
. Because of this mismatch, firebase was actually loaded into memory twice, but only instantiated once.
The docs suggest that the code you put in the providers should the in the imports.
import { provideFirebaseApp, getApp, initializeApp } from '@angular/fire/app';
import { getFirestore, provideFirestore } from '@angular/fire/firestore';
@NgModule({
imports: [
provideFirebaseApp(() => initializeApp({ ... })),
provideFirestore(() => getFirestore()),
],
...
})
export class AppModule { }
Yes, do an ng-update - update all pkgs listed
Humm.. ok, I am using version 9 upgraded from 8 in my project, and either you mented out some things or you indeed are missing some stuff. Let me share my module:
const providers = [
// ...
AngularFireModule,
AngularFireAnalyticsModule,
AngularFireAuthGuard,
ScreenTrackingService,
UserTrackingService,
AngularFireAnalytics,
{
provide: ANALYTICS_CONFIG,
useValue: {
APP_NAME: appConfig.appName,
APP_VERSION: appConfig.appVersion
}
}
];
@NgModule({
imports: [
// ...
/** Firebase Modules */
AngularFireModule.initializeApp(firebaseConfig),
AngularFireAnalyticsModule,
AngularFireAuthGuardModule,
AngularFireDatabaseModule,
AngularFireFunctionsModule,
// ...
],
providers,
bootstrap: [RootComponent]
})
So my initialize app is at my imports and not on my providers, I remember I had some issues back then and after some digging and changing I came up with the above and it worked for me. As you can see I use quite a few of their services.
From the error you posted, I would guess the problem is your initializeApp
not doing the initialization, so make try to move it to imports and make sure the config file has all the required properties.
==UPDATE==
Please note that I pasted my project imports, you may ignore everything else other than the AngularFireModule
import and providers, since you may not use the others, I just added them for reference as they could be useful to other people.
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745309525a4621918.html
评论列表(0条)