简体   繁体   English

最新 @angular/fire 中的错误:Firebase:没有创建 Firebase 应用程序“[DEFAULT]” - 调用 Firebase App.initializeApp()

[英]Error in latest @angular/fire: Firebase: No Firebase App '[DEFAULT]' has been created - call Firebase App.initializeApp()

I've upgraded to the latest version of @angular/fire recently, and everything worked fine, but now I've migrated away from the compat libraries, and now I'm stuck with this issue.我最近升级到最新版本的@angular/fire,一切正常,但现在我已经从兼容库中迁移出来,现在我被这个问题困住了。 I get this error on the following code: Firebase: No Firebase App '[DEFAULT]' has been created - call Firebase App.initializeApp() .我在以下代码中收到此错误: 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!任何帮助深表感谢!

Humm.. ok, I am using version 9 upgraded from 8 in my project, and either you commented out some things or you indeed are missing some stuff.嗯.. 好的,我在我的项目中使用从 8 升级的版本 9,要么你注释掉了一些东西,要么你确实遗漏了一些东西。 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.根据您发布的错误,我猜问题是您的initializeApp没有进行初始化,因此请尝试将其移动到导入并确保配置文件具有所有必需的属性。

Apparently the issue was a mismatch in versions between firebase and @firebase/app .显然,问题是firebase@firebase/app之间的版本不匹配。 Because of this mismatch, firebase was actually loaded into memory twice, but only instantiated once.由于这种不匹配,firebase 实际上被加载到内存中两次,但只实例化了一次。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 错误:没有 Firebase 应用程序“[DEFAULT]”已创建 - 调用 Firebase App.initializeApp() - Error: No Firebase App '[DEFAULT]' has been created - call Firebase App.initializeApp() 未捕获的 FirebaseError:Firebase:否 Firebase 应用程序“[DEFAULT]”已创建 - 调用 Firebase App.initializeApp() - 在 React.js 中 - Uncaught FirebaseError: Firebase: No Firebase App '[DEFAULT]' has been created - call Firebase App.initializeApp() (app/no-app). - In React.js Uncaught FirebaseError: Firebase: No Firebase App '[DEFAULT]' has been created - call Firebase App.initializeApp() (app/no-app) in vue.js - Uncaught FirebaseError: Firebase: No Firebase App '[DEFAULT]' has been created - call Firebase App.initializeApp() (app/no-app) in vue.js Firebase:没有创建 Firebase App '[DEFAULT]' - 调用 Firebase App.initializeApp() (app-compat/no-app) - Firebase: No Firebase App '[DEFAULT]' has been created - call Firebase App.initializeApp() (app-compat/no-app) Uncaught FirebaseError: Firebase: No Firebase App '[DEFAULT]' 已创建 - 调用 Firebase App.initializeApp() (app/no-app) - Uncaught FirebaseError: Firebase: No Firebase App '[DEFAULT]' has been created - call Firebase App.initializeApp() (app/no-app) 未创建 Firebase 应用“[默认] - 调用 firebase.initializeApp() - No Firebase App '[Default] has been created - call firebase.initializeApp() 'No Firebase App '[DEFAULT]' has been created' 即使调用了 initializeApp - 'No Firebase App '[DEFAULT]' has been created' even though initializeApp is called firebase function、Firebase 中的错误:没有创建 Z035489FF8D092741943E4A89 应用程序'DEFA'2 - error in firebase function, Firebase: No Firebase App '[DEFAULT]' has been created Firebase 错误:尚未创建 Firebase 应用 - Firebase Error: No Firebase App has been created app.initializeApp 在使用 Firebase Class 时不是 function - app.initializeApp is not a function when using Firebase Class
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM