问题描述
ERROR in node_modules/@angular/fire/firestore/firestore.module.d.ts:7:74 - error TS2314: Generic type 'ModuleWithProviders<T>' requires 1 type argument(s).
7 static enablePersistence(persistenceSettings?: PersistenceSettings): ModuleWithProviders;
在将firebase添加到Angular 10项目中时出现上述错误。 (旧的angular 9项目没有问题)
我添加Firebase的步骤
-
npm install firebase @ angular / fire --save
-
ng添加@ angular / fire
-
更新了 environment.ts
production: false,firebase: {
apiKey: <secret>,authDomain: <secret>,databaseURL: <secret>,projectId: <secret>,storageBucket: <secret>,messagingSenderId: <secret>,appId: <secret>,measurementId: <secret>
}
};
- 更新了 app.module.ts
// Firebase imports
import { AngularFireModule } from '@angular/fire';
import { AngularFirestoreModule} from '@angular/fire/firestore';
import { environment } from '../environments/environment';
@NgModule({
declarations: [
AppComponent
],imports: [
QuicklinkModule,BrowserModule,AppRoutingModule,BrowserAnimationsModule,FlexLayoutModule,SharedModule,AngularFireModule.initializeApp(environment.firebase),// Main Angular fire module
AngularFirestoreModule
],providers: [],bootstrap: [AppComponent]
})
export class AppModule { }
解决方法
这是Firestore库中的错误。它刚刚修复:
https://github.com/angular/angularfire/commit/93912bc3e9e41d48628a8671c766b0c2e8b65dc8
尝试将依赖项更新到最新版本。那应该可以解决问题。
,GitHub issue的解决方法
工作:更新 tsconfig.app.json
/* To learn more about this file see: https://angular.io/config/tsconfig. */
{
"extends": "./tsconfig.base.json","compilerOptions": {
"outDir": "./out-tsc/app","types": [],"skipLibCheck": true
},"files": [
"src/main.ts","src/polyfills.ts"
],"include": [
"src/**/*.d.ts"
]
}
,追加“ skipLibCheck”:是
在另一个答案中指出,此问题已得到解决:https://github.com/angular/angularfire/commit/93912bc3e9e41d48628a8671c766b0c2e8b65dc8
但是您使用的@ angular / fire的最新版本 stable 中未包含该文件(6月下旬发布的6.0.2版)。但是,有一个可用的修补程序版本,它不是稳定版本,但已修复。如果将@ angular / fire的版本更改为6.0.3-canary.93912bc,它将与最新的Angular 10版本一起使用。
,我安装了最新版本的angular,并遇到了同样的问题,只需添加此行:
"skipLibCheck": true;
到 tconfig.app.json
{
"extends": "./tsconfig.json","files": ["src/main.ts","src/polyfills.ts"],"include": ["src/**/*.d.ts"]
}