非法状态:无法加载指令 NgClass 的摘要

Illegal state: Could not load the summary for directive NgClass

当我的模块上 运行 ngc 时,它过去使用 angular 4.4.3(和编译器 4.4.3)可以正常工作。现在我升级到 5.0.0(angular 和编译器),我有以下错误:

Error: Illegal state: Could not load the summary for directive NgClass in [...]/node_modules/@angular/common/common.d.ts.

我的 tsconfig.json 文件如下所示:

{
  "compilerOptions": {
    "baseUrl": ".",
    "declaration": true,
    "stripInternal": true,
    "experimentalDecorators": true,
    "emitDecoratorMetadata": true,
    "module": "es2015",
    "moduleResolution": "node",
    "outDir": "[...]/",
    "paths": {...},
    "rootDir": "[...]/plugins/",
    "target": "es5",
    "skipLibCheck": true,
    "lib": [
      "es2015",
      "dom"
    ],
    "sourceMap": true,
    "inlineSources": true,
    "noImplicitAny": true
  },
  "files": [
    "[...]/plugins/users/index.ts"
  ]
}

我不知道是什么原因导致我尝试编译的文件出现问题。我在这里和那里看到过类似的错误,但与公共模块没有直接关系。很难 post 一个示例来重现错误,因为它不会发生在其他模块上

编辑 1:

我的设置如下:一个模块 MyModuleA 构建成功,MyModuleB 使用 MyModuleA 未构建。

@NgModule({
  imports: [
    CommonModule,
    IonicModule,
    TranslateModule.forChild()
  ]
})
export class MyModuleA {
  static forRoot(): ModuleWithProviders {
    return {
      ngModule: MyModuleA,
      providers: [
        ModuleAService
      ]
    };
  }
}

@NgModule({
  imports: [
    HttpClientModule,
    MyModuleA
  ]
})
export class MyModuleB {
  /**
   * Instantiate module (for main module only).
   */
  static forRoot(): ModuleWithProviders {
    return {
      ngModule: MyModuleB,
      providers: [
        ModuleBService
      ]
    }
  }
}

如果我在 MyModuleB 中包含 CommonModule,则会出现另一个错误:

Error: Illegal state: Could not load the summary for directive ActionSheetCmp in [...]/node_modules/ionic-angular/components/action-sheet/action-sheet-component.d.ts

现在我可以在 MyModuleB 中包含 IonicModule 以获得下一个 illegal state error(这次链接到翻译模块),但我根本没有在 MyModuleB 为什么我需要全部导入它们?

所以我不确定这背后的原因是什么,这很烦人,但似乎每个导入的模块都需要由 sub-module 导入或从父模块导出。所以在我的例子中,解决方案是:

@NgModule({
  imports: [
    CommonModule,
    IonicModule,
    TranslateModule.forChild()
  ],
  exports: [
    CommonModule,
    IonicModule,
    TranslateModule
  ]
})
export class MyModuleA {
  static forRoot(): ModuleWithProviders {
    return {
      ngModule: MyModuleA,
      providers: [
        ModuleAService
      ]
    };
  }
}

@NgModule({
  imports: [
    HttpClientModule,
    MyModuleA
  ]
})
export class MyModuleB {
  /**
   * Instantiate module (for main module only).
   */
  static forRoot(): ModuleWithProviders {
    return {
      ngModule: MyModuleB,
      providers: [
        ModuleBService
      ]
    }
  }
}

有谁知道为什么,不吝赐教:)