我正在尝试将Angle 8项目升级到Angular 9,但是出现以下错误:
fail: Microsoft.AspNetCore.SpaServices[0] ERROR in ./src/main.ts Module build failed (from ./node_modules/@ngtools/webpack/src/index.js): Error:
C:\ deacted \ redacted \ redacted \ src \ main.ts从 TypeScript编译。请通过以下方式确保它在您的tsconfig中 “文件”或“包含”属性。 在AngularCompilerPlugin.getCompiledFile(C:\ redacted \ redacted \ redacted \ node_modules @ ngtools \ webpack \ src \ angular_compiler_plugin.js:933:23) 在C:\ redacted \ redacted \ redacted \ node_modules @ ngtools \ webpack \ src \ loader.js:41:31 在processTicksAndRejections(internal / process / task_queues.js:89:5)中的错误在./src/polyfills.ts中 模块构建失败(来自 ./node_modules/@ngtools/webpack/src/index.js):错误: C:\ redacted \ redacted \ redacted \ src \ polyfills.ts从 TypeScript编译。请通过以下方式确保它在您的tsconfig中 “文件”或“包含”属性。 在AngularCompilerPlugin.getCompiledFile(C:\ redacted \ redacted \ redacted \ node_modules @ ngtools \ webpack \ src \ angular_compiler_plugin.js:933:23) 在C:\ redacted \ redacted \ redacted \ node_modules @ ngtools \ webpack \ src \ loader.js:41:31 在processTicksAndRejections(internal / process / task_queues.js:89:5)
我知道Stackoverflow上有一些类似的线程,但是似乎没有一个答案适合我的情况。我在angular.json中插入了““ preserveSymlinks”:true“,并且尝试将整个项目移至c:。 main.ts和polyfills.ts位于,它表示不存在,所以很混乱。
angular.json
{
"$schema": "./node_modules/@angular/cli/lib/config/schema.json",
"version": 1,
"newProjectRoot": "projects",
"projects": {
"our-project": {
"root": "",
"sourceRoot": "src",
"projectType": "application",
"architect": {
"build": {
"builder": "@angular-devkit/build-angular:browser",
"options": {
"preserveSymlinks": true,
"aot": true,
"outputPath": "dist/browser",
"index": "src/index.html",
"main": "src/main.ts",
"tsConfig": "src/tsconfig.app.json",
"polyfills": "src/polyfills.ts",
"assets": ["src/assets"],
"styles": [
"src/assets/styles/app/icons.css",
"src/assets/styles/app/icons.alias.css",
"src/assets/styles/lib/animate.css",
"src/assets/styles/app/site.less",
"src/assets/styles/app/start.less",
"src/assets/styles/app/animations.less",
"src/assets/styles/app/topimages.less",
"src/assets/styles/app/style-apploading.less",
"src/assets/styles/app/style.scss",
"src/assets/styles/app/menu.less"
],
"scripts": []
},
"configurations": {
"production": {
"budgets": [
{
"type": "anyComponentStyle",
"maximumWarning": "30kb"
}
],
"optimization": true,
"outputHashing": "all",
"sourceMap": true,
"extractCss": true,
"namedChunks": false,
"aot": true,
"extractLicenses": true,
"vendorChunk": false,
"buildOptimizer": true,
"fileReplacements": [
{
"replace": "src/environments/environment.ts",
"with": "src/environments/environment.prod.ts"
}
]
},
"es5": {
"budgets": [
{
"type": "anyComponentStyle",
"maximumWarning": "30kb"
}
],
"tsConfig": "./tsconfig.es5.json"
}
}
},
...
tsconfig.app.json
{
"extends": "../tsconfig.json",
"compilerOptions": {
"outDir": "../out-tsc/app",
"baseUrl": "",
"types": ["node"]
},
"files": ["main.ts", "polyfills.ts"],
"include": ["**/*.d.ts"],
"includes": ["../node_modules/our-typescript-api/AngularApi.js"]
}
答案 0 :(得分:0)
花了半天的时间解决这个问题后,我在发布问题5分钟后才发现问题所在!
因此,在tsconfig.app.json中不要包含:“” files“:[” main.ts“,” polyfills.ts“]”,而应在tsconfig.json中(但以src /开头)