【发布时间】:2019-09-20 08:57:02
【问题描述】:
我正在尝试在我的应用程序中连接 firebase,但我遇到了同样的错误,我尝试了很多方法,但都没有奏效。 首先,我安装了 firebase 和 @angular/fire
npm install firebase @angular/fire --save
之后,我将 environment.ts 更改为
export const environment = {
production: false,
firebase: {
apiKey: "XXXXXXXXXXXXXXXXXXXXXXXXX",
authDomain: "XXXXXXXXXXXXXXXXXXXXXXXXXX",
databaseURL: "XXXXXXXXXXXXXXXXXXXXXXXXXXXX",
projectId: "XXXXXXXXXXXXXXXXXXXXXXXXXX",
storageBucket: "XXXXXXXXXXXXXXXXXXXXXXXXX",
messagingSenderId: "XXXXXXXXXXXXXXXXXXXX"
}
};
正如文档所说。 (我放了 XX,但在真实环境中。ts o 放正确的)。然后,我将 app.module.ts 更改为
import { NgModule } from '@angular/core';
...
import { AngularFireModule } from '@angular/fire';
import { environment } from '../environments/environment';
@NgModule({
declarations: [AppComponent],
entryComponents: [],
imports: [BrowserModule, IonicModule.forRoot(), AppRoutingModule,
AngularFireModule.initializeApp(environment.firebase, 'guarnice')],
providers: [
StatusBar,
SplashScreen,
{ provide: RouteReuseStrategy, useClass: IonicRouteStrategy }
],
bootstrap: [AppComponent]
})
export class AppModule {}
当我运行代码时
ionic serve
我有错误。
node_modules/@angular/fire/firebase.app.module.d.ts(17,22) 中的错误:错误 TS2420:“FirebaseApp”类错误地实现了“App”接口。 “FirebaseApp”类型中缺少属性“性能”。
然后我寻找 firebase.app.module.d.ts 然后
import { InjectionToken } from '@angular/core';
import { app, auth, database, firestore, functions, messaging, storage } from 'firebase/app';
export declare type FirebaseOptions = {
[key: string]: any;
};
export declare type FirebaseAppConfig = {
[key: string]: any;
};
export declare const FirebaseOptionsToken: InjectionToken<FirebaseOptions>;
export declare const FirebaseNameOrConfigToken: InjectionToken<string | FirebaseAppConfig | undefined>;
export declare type FirebaseDatabase = database.Database;
export declare type FirebaseAuth = auth.Auth;
export declare type FirebaseMessaging = messaging.Messaging;
export declare type FirebaseStorage = storage.Storage;
export declare type FirebaseFirestore = firestore.Firestore;
export declare type FirebaseFunctions = functions.Functions;
export declare class FirebaseApp implements app.App {
name: string;
options: {};
auth: () => FirebaseAuth;
database: (databaseURL?: string) => FirebaseDatabase;
messaging: () => FirebaseMessaging;
storage: (storageBucket?: string) => FirebaseStorage;
delete: () => Promise<void>;
firestore: () => FirebaseFirestore;
functions: (region?: string) => FirebaseFunctions;
}
export declare function _firebaseAppFactory(options: FirebaseOptions, nameOrConfig?: string | FirebaseAppConfig | null): FirebaseApp;
export declare class AngularFireModule {
static initializeApp(options: FirebaseOptions, nameOrConfig?: string | FirebaseAppConfig): {
ngModule: typeof AngularFireModule;
providers: {
provide: InjectionToken<string | FirebaseAppConfig | undefined>;
useValue: string | FirebaseAppConfig | undefined;
}[];
};
}
我不知道我必须如何解决它...我在 stackoverflow 和其他网站上看到了一些小技巧,但没有一个有效。
这是我关注的文档https://github.com/angular/angularfire2
Angular CLI: 7.3.8
Node: 10.15.3
OS: linux x64
Angular: 7.2.13
Ionic: 4.12.0
Package Version
-----------------------------------------------------------
@angular-devkit/architect 0.12.4
@angular-devkit/build-angular 0.13.8
@angular-devkit/build-optimizer 0.13.8
@angular-devkit/build-webpack 0.13.8
@angular-devkit/core 7.2.4
@angular-devkit/schematics 7.2.4
@angular/cli 7.3.8
@angular/fire 5.1.2
@ngtools/webpack 7.3.8
@schematics/angular 7.3.8
@schematics/update 0.13.8
rxjs 6.4.0
typescript 3.1.6
webpack 4.29.0
【问题讨论】:
标签: javascript angular firebase ionic-framework angularfire2