我目前正在努力构建我的Angular 7应用程序(最近从v6更新)。
运行ng build
可以很好,但是,ng serve --aot
,ng build --aot
或ng 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"
]
}
能帮我解决这个问题吗? 谢谢。
答案 0 :(得分:0)
我找到了解决问题的方法:
我在应用程序的所有位置检查了import
文件的所有.d.ts
语句。
一个错误(错误的路径),如果没有--aot
标志,这似乎不是问题。
也许会帮助某人。
答案 1 :(得分:-2)
在types
中将typeRoots
键更改为tsconfig.app.json
,因为要指定文件夹而不是特定文件。