角度7 |生成--aot失败|编译缺少Typescript .d.ts声明文件

时间:2018-11-21 19:25:56

标签: angular typescript build angular7

我目前正在努力构建我的Angular 7应用程序(最近从v6更新)。

运行ng build可以很好,但是,ng serve --aotng build --aotng build --prod(也可以启用aot)会导致以下错误

Typescript编译器无法找到我的拥有 .d.ts 文件,这些文件全部位于src/app/types/中。

我试图通过将这些文件的路径添加到include文件的tsconfig.app.json属性中来解决此问题,但此方法无效。

请注意,问题与Angular v6相同。

ERROR in ./src/app/types/data.d.ts
Module build failed (from ./node_modules/@ngtools/webpack/src/index.js):
Error: /xxx/src/app/types/data.d.ts is missing from the TypeScript compilation. Please make sure it is in your tsconfig via the 'files' or 'include' property.
at AngularCompilerPlugin.getCompiledFile (/xxxx/node_modules/@ngtools/webpack/src/angular_compiler_plugin.js:767:23)
at plugin.done.then (/xxxx/node_modules/@ngtools/webpack/src/loader.js:41:31)
at <anonymous>
at process._tickCallback (internal/process/next_tick.js:188:7)

这是tsconfig.json文件:

{
  "compileOnSave": false,
  "compilerOptions": {
    "baseUrl": "./",
    "outDir": "./dist/out-tsc",
    "sourceMap": true,
    "declaration": false,
    "module": "es2015",
    "moduleResolution": "node",
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "target": "es5",
    "typeRoots": [
      "node_modules/@types"
    ],
    "lib": [
      "es2017",
      "dom"
    ]
  }
}

这是tsconfig.app.json文件:

{
  "extends": "../tsconfig.json",
  "compilerOptions": {
    "outDir": "../out-tsc/app",
    "types": ["node"]
  },
  "exclude": [
    "src/test.ts",
    "**/*.spec.ts"
  ]
}

能帮我解决这个问题吗? 谢谢。

2 个答案:

答案 0 :(得分:0)

我找到了解决问题的方法: 我在应用程序的所有位置检查了import文件的所有.d.ts语句。 一个错误(错误的路径),如果没有--aot标志,这似乎不是问题。 也许会帮助某人。

答案 1 :(得分:-2)

types中将typeRoots键更改为tsconfig.app.json,因为要指定文件夹而不是特定文件。