GoogleApiModule无法解析为NgModule类

时间:2020-04-16 05:05:44

标签: angular npm-install google-api-js-client

尝试按照https://www.npmjs.com/package/ng-gapi上的说明导入GoogleApiModule,但是我遇到了错误

ERROR in node_modules/ng-gapi/lib/GoogleApiModule.d.ts:2:22 - error NG6002: Appears in the NgModule.imports of AppModule, but could not be resolved to an NgModule class.

    This likely means that the library (ng-gapi) which declares GoogleApiModule has not been processed correctly by ngcc, or is not compatible with Angular Ivy. Check if a newer version of the library is available, and update if so. Also consider checking with the library's authors to see if the library is expected to be compatible with Ivy.

    2 export declare class GoogleApiModule {
                           ~~~~~~~~~~~~~~~

这是我尝试过的: (在app.module.ts中)

imports: [
    BrowserModule,
    FormsModule,
    GoogleApiModule.forRoot({
      provide: NG_GAPI_CONFIG,
      useValue: gapiClientConfig
    })

我还尝试仅引用从ngModule返回的ModuleWithProviders<GoogleApiModule>的{​​{1}}成员,这也会产生错误。

有什么方法可以注入这项服务吗?

注意:我试图将GoogleApiModule.forRoot()中的"enableIvy": false设置为无用(并且也给出了新的错误)。

1 个答案:

答案 0 :(得分:0)

我通过同时禁用AOT 常春藤解决了该问题。

tsconfig.json中的

  "angularCompilerOptions": {
    "fullTemplateTypeCheck": true,
    "strictInjectionParameters": true,
    "enableIvy": false
  }

在package.json中:

"build": {
.
.
.
    "aot": false,
.
.