Firebase:未创建Firebase应用程序'[DEFAULT]'-调用Firebase App.initializeApp()(app / no-app)

时间:2018-10-01 16:47:17

标签: firebase

首先,很抱歉,这是我第一次在论坛上提问,而且英语说得不太好... 我正在使用Ionic 3开发应用程序,尝试使用Firebase时出现此错误:

Firebase:未创建Firebase应用程序'[DEFAULT]'-调用Firebase App.initializeApp()(app / no-app)

这是我的文件:

App.module.ts:

import { BrowserModule } from '@angular/platform-browser';
import { ErrorHandler, NgModule } from '@angular/core';
import { IonicApp, IonicErrorHandler, IonicModule } from 'ionic-angular';
import { SplashScreen } from '@ionic-native/splash-screen';
import { StatusBar } from '@ionic-native/status-bar';

import { AngularFireModule } from 'angularfire2';
import { AngularFireAuthModule } from 'angularfire2/auth';

import { MyApp } from './app.component';
import { HomePage } from '../pages/home/home';
import {TabsPage} from "../pages/tabs/tabs";
import {ListPage} from "../pages/list/list";
import {AuthPage} from "../pages/auth/auth";
import {AuthService} from "../Services/Authentification/auth.service";
import {FIREBASE_CONFIG} from "./app.firebase.config";

    @NgModule({
      declarations: [
        MyApp,
        HomePage,
        TabsPage,
        ListPage,
        AuthPage,
      ],
      imports: [
        BrowserModule,
        IonicModule.forRoot(MyApp),
        AngularFireModule.initializeApp(FIREBASE_CONFIG),
        AngularFireAuthModule,
      ],
      bootstrap: [IonicApp],
      entryComponents: [
        MyApp,
        HomePage,
        TabsPage,
        ListPage,
        AuthPage,
      ],
      providers: [
        StatusBar,
        SplashScreen,
        {provide: ErrorHandler, useClass: IonicErrorHandler},
        AuthService,
      ]
    })
    export class AppModule {}

app.firebase.config:

export const FIREBASE_CONFIG = {

  apiKey: "...",
  authDomain: "...",
  databaseURL: "...",
  projectId: "...",
  storageBucket: "...",
  messagingSenderId: "..."

};

我已经在其他论坛上搜索了解决方案,但没有任何效果。 如果您需要更多信息,请告诉我

1 个答案:

答案 0 :(得分:1)

我猜测您的Firebase_config定义的文件路径可能有问题。不久前我离开了angularFire,但是我记得初始化是相似的。这是下面的我的app.module.ts文件...因此,也许您可​​以尝试以下操作:

import { NgModule } from '@angular/core'; 
import { BrowserModule } from '@angular/platform-browser'; 
import { RouterModule, RouteReuseStrategy, Routes } 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 * as firebase from 'firebase';

      // Initialize Firebase   export const config = {
        apiKey: "CENSORED",
        authDomain: "CENSORED.firebaseapp.com",
        databaseURL: "https://CENSORED.firebaseio.com",
        projectId: "CENSORED-fffff",
        storageBucket: "sCENSORED-fffff.appspot.com",
        messagingSenderId: "CENSORED"   };

      firebase.initializeApp(config);     <-------------------initialize here



@NgModule({
  declarations: [
    AppComponent, 
    LoginFormComponent, 
   ],
  entryComponents: [
  ],
  imports: [
    BrowserModule, 
    IonicModule.forRoot(),               <----No mention of firebase down here
    AppRoutingModule,
    IonicStorageModule.forRoot(),
  ],
  providers: [
    AuthenticationService,
    StatusBar,
    SplashScreen,
    { provide: RouteReuseStrategy, useClass: IonicRouteStrategy }
  ],
  bootstrap: [AppComponent]
})
export class AppModule {}