错误:尚未创建 Firebase 应用“[DEFAULT]” - 调用 Firebase App.initializeApp()

我有一个firebase数据库,最多链接到两个应用程序,一个是iOS应用程序,另一个是node中编码的Web应用程序.js这是将数据设置为数据库的基本算法。每当我运行算法时,我都会遇到 -

错误:尚未创建 Firebase 应用“[DEFAULT]” - 调用 Firebase App.initializeApp()。在 Object.c [as database] (/Users/dd/Desktop/Desktop/Desktop/Node/node_modules/firebase/app-node.js/node/node_modules/firebase/app-.js node.js:21:447) 处的 R (/Users/node_modules dd/Code/app-node.js/user/desktop/code/NODE/node_modules/firebase/app-node.js:21:447) 处的错误(本机)。(/Users/dd/Desktop/Code/NODE/Bot.js:24:25) at Module._compile (module.js:570:32) at Object.Module._extensions..js (module.js:579:10) at Module.load (module.js:487:32) at tryModuleLoad (module.js:446:12) at Function.Module._load (module.js:438:3) at Module.runMain (module.js:604:10) at run (bootstrap_node.js:394:7) at startup (bootstrap_node.js:149:9) at bootstrap_node.js:509:3 dd-mac:NODE dd$

有人可以帮忙吗?


答案 1

您可能在初始化应用之前调用。所有呼叫必须稍后再来firebasefirebase .initializeApp();

firebase.initializeApp(config);
var db = firebase.firestore();

答案 2

完整的教程链接

在@NgModule之前使用 initializeApp

import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { RouteReuseStrategy } from '@angular/router';

import { IonicModule, IonicRouteStrategy } from '@ionic/angular';
import { SplashScreen } from '@ionic-native/splash-screen/ngx';
import { StatusBar } from '@ionic-native/status-bar/ngx';

import { AppComponent } from './app.component';
import { AppRoutingModule } from './app-routing.module';
import { environment } from 'src/environments/environment';
import { AuthenticateService } from './services/authentication.service';
import { AngularFireAuthModule } from '@angular/fire/auth';

import * as firebase from 'firebase';

firebase.initializeApp(environment.firebase);

@NgModule({
  declarations: [AppComponent],
  entryComponents: [],
  imports: [
    BrowserModule, 
    IonicModule.forRoot(), 
    AppRoutingModule,
    AngularFireAuthModule
  ],
  providers: [
    StatusBar,
    SplashScreen,
    AuthenticateService,
    { provide: RouteReuseStrategy, useClass: IonicRouteStrategy }
  ],
  bootstrap: [AppComponent]
})
export class AppModule {}