错误:非法状态:无法在 node_modules/@angular/cdk/observers/typings/index.d.ts 中加载指令 CdkObserveContent 的摘要

ERROR in : Illegal state: Could not load the summary for directive CdkObserveContent in node_modules/@angular/cdk/observers/typings/index.d.ts

我的 Angular 5 应用程序出现如下错误。我正在使用来自 VSCode.

Angular CLI 和 运行

ERROR in : Illegal state: Could not load the summary for directive CdkObserveContent in node_modules/@angular/cdk/observers/typings/index.d.ts.

仅当我执行 ng build --prod 时才会抛出错误。命令 ng serveng build 可以正常工作。

知道吗,可能是什么原因?

好的,让我回答我自己的问题。这真是奇怪。我已将 tsconfig.json 文件中的 rootDir 的值更改为 .,从而解决了此处的问题。 post 确实帮助我做到了这一点。我不确定 ng build --prod 与此 rootDir 有什么关系。现在所有的命令都工作正常。

上一个tsconfig.json

{
  "compileOnSave": false,
  "compilerOptions": {
    "module": "commonjs",
    "target": "ES5",
    "outDir": "bin",
    "rootDir": "src",
    "sourceMap": true,
    "declaration": false,
    "moduleResolution": "node",
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "typeRoots": [
      "node_modules/@types"
    ],
    "lib": [
      "es2017",
      "dom"
    ]
  }
}

新建tsconfig.json

{
  "compileOnSave": false,
  "compilerOptions": {
    "module": "commonjs",
    "target": "ES5",
    "outDir": "bin",
    "rootDir": ".",
    "sourceMap": true,
    "declaration": false,
    "moduleResolution": "node",
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "typeRoots": [
      "node_modules/@types"
    ],
    "lib": [
      "es2017",
      "dom"
    ]
  }
}

希望对您有所帮助。