Error: No Firebase App '[DEFAULT]' has been created - call Firebase App.initializeApp()

后端 未结 9 665
慢半拍i
慢半拍i 2020-12-01 15:55

I have a firebase database linked up to two apps, one being an iOS app and another being a web app coded in node.js which is a basic algorithm that sets data to the database

相关标签:
9条回答
  • 2020-12-01 16:06

    Flutter web

    For me the error occurred when I run my application in "release" mode

    flutter run -d chrome --release

    and when I deployed the application on the Firebase hosting

    firebase deploy

    Solution

    Since I initialized Firebase in the index.html, I had to change the implementation order of firebase and main.dart.js

    <script>
      var firebaseConfig = {
      apiKey: "xxxxxxxxxxxxxxxxxxxxxx",
      authDomain: "xxxxxxxxxxx.firebaseapp.com",
      databaseURL: "https://xxxxxxxxxx.firebaseio.com",
      projectId: "xxxxxxxxxxx",
      storageBucket: "xxxxxxxx.appspot.com",
      messagingSenderId: "xxxxxxxxxxx",
      appId: "1:xxxxxxxxxx:web:xxxxxxxxxxxxx",
      measurementId: "G-xxxxxxxxx"
      };
      // Initialize Firebase
      firebase.initializeApp(firebaseConfig);
      firebase.analytics();
    </script>
    
    //moved below firebase init
    <script src="main.dart.js" type="application/javascript"></script>
    
    0 讨论(0)
  • 2020-12-01 16:18

    Complete tutorial source link

    Use initializeApp before @NgModule

    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 {}
    
    0 讨论(0)
  • 2020-12-01 16:18

    I had a similar issue following Firebase's online guide found here.

    The section heading "Initialize multiple apps" is misleading as the first example under this heading actually demonstrates how to initialize a single, default app. Here's said example:

    // Initialize the default app
    var defaultApp = admin.initializeApp(defaultAppConfig);
    
    console.log(defaultApp.name);  // "[DEFAULT]"
    
    // Retrieve services via the defaultApp variable...
    var defaultAuth = defaultApp.auth();
    var defaultDatabase = defaultApp.database();
    
    // ... or use the equivalent shorthand notation
    defaultAuth = admin.auth();
    defaultDatabase = admin.database();
    

    If you are migrating from the previous 2.x SDK you will have to update the way you access the database as shown above, or you will get the, No Firebase App '[DEFAULT]' error.

    Google has better documentation at the following:

    1. INITIALIZE: https://firebase.google.com/docs/database/admin/start

    2. SAVE: https://firebase.google.com/docs/database/admin/save-data

    3. RETRIEVE: https://firebase.google.com/docs/database/admin/retrieve-data

    0 讨论(0)
提交回复
热议问题