Angular 7 |构建--aot 失败 |编译中缺少 Typescript .d.ts 声明文件
Angular 7 | Build --aot fails | Typescript .d.ts declaration files missing from compilation
我目前正在努力构建我的 Angular 7 应用程序(最近从 v6 更新)。
运行 ng build
工作 很好 ,但是,ng serve --aot
、ng build --aot
或 ng build --prod
(这也启用 aot)导致以下错误。
Typescript 编译器无法找到我的 own .d.ts
文件都位于 src/app/types/
.
我试图通过将这些文件的路径添加到 tsconfig.app.json
文件的 include
属性 中来解决这个问题,但是没有成功。
请注意,问题与 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"
]
}
你能帮我解决这个问题吗?
谢谢。
将 tsconfig.app.json
中的 types
键更改为 typeRoots
,因为您指定的是文件夹而不是特定文件。
我找到了问题的解决方案:
我在我的应用程序中到处检查了 .d.ts
文件的所有 import
语句。
一个是错误的(错误的路径),如果没有 --aot
标志,这似乎不是问题。
也许这会对某人有所帮助。
我目前正在努力构建我的 Angular 7 应用程序(最近从 v6 更新)。
运行 ng build
工作 很好 ,但是,ng serve --aot
、ng build --aot
或 ng build --prod
(这也启用 aot)导致以下错误。
Typescript 编译器无法找到我的 own .d.ts
文件都位于 src/app/types/
.
我试图通过将这些文件的路径添加到 tsconfig.app.json
文件的 include
属性 中来解决这个问题,但是没有成功。
请注意,问题与 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"
]
}
你能帮我解决这个问题吗? 谢谢。
将 tsconfig.app.json
中的 types
键更改为 typeRoots
,因为您指定的是文件夹而不是特定文件。
我找到了问题的解决方案:
我在我的应用程序中到处检查了 .d.ts
文件的所有 import
语句。
一个是错误的(错误的路径),如果没有 --aot
标志,这似乎不是问题。
也许这会对某人有所帮助。