angular - 在升级到 Angular 9 期间,Typescript 编译中缺少 main.ts 和 polyfills.ts

标签 angular asp.net-core webpack

我正在尝试将 Angular 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:\redacted\redacted\redacted\src\main.ts is missing from the TypeScript compilation. Please make sure it is in your tsconfig via the 'files' or 'include' property. at AngularCompilerPlugin.getCompiledFile (C:\redacted\redacted\redacted\node_modules@ngtools\webpack\src\angular_compiler_plugin.js:933:23) at C:\redacted\redacted\redacted\node_modules@ngtools\webpack\src\loader.js:41:31 at processTicksAndRejections (internal/process/task_queues.js:89:5) ERROR in ./src/polyfills.ts Module build failed (from ./node_modules/@ngtools/webpack/src/index.js): Error: C:\redacted\redacted\redacted\src\polyfills.ts is missing from the TypeScript compilation. Please make sure it is in your tsconfig via the 'files' or 'include' property. at AngularCompilerPlugin.getCompiledFile (C:\redacted\redacted\redacted\node_modules@ngtools\webpack\src\angular_compiler_plugin.js:933:23) at C:\redacted\redacted\redacted\node_modules@ngtools\webpack\src\loader.js:41:31 at processTicksAndRejections (internal/process/task_queues.js:89:5)

我知道 Stackoverflow 上有一些类似的讨论帖,但似乎没有一个答案适合我的情况。我已将 ""preserveSymlinks": true"插入到 angular.json 中,并尝试将我的整个项目移动到 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"]
}

最佳答案

我花了半天时间解决这个问题,发布问题5分钟后我发现了问题!

因此,与其在 tsconfig.app.json 中包含:""files": ["main.ts", "polyfills.ts"]",不如在 tsconfig.json 中(但以 src/开头)

关于angular - 在升级到 Angular 9 期间,Typescript 编译中缺少 main.ts 和 polyfills.ts,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64446134/

相关文章:

asp.net-core - HttpRequestMessage.Content 在接收 Controller 操作时为空

angular - 如何在 Ionic2 中显示网速慢的警报?

angular - TypeScript,Angular如何将列表中对象的属性转换为以逗号分隔的字符串

c# - 尚未注册类型 'Microsoft.AspNetCore.Hosting.IHostingEnvironment' 的服务

node.js - 将变量从 NPM 脚本传递到 Webpack

javascript - TypeError [ERR_INVALID_ARG_TYPE] : The "data" argument must be of type string or an instance of Buffer, TypedArray,或DataView

webpack - 如何使用代码拆分在 Vue/Webpack webapp 中部分加载 Sass/样式表文件

angular - 使用 Angular 2 使用 ag-grid 提前输入

javascript - 如果满足条件则有 Angular 动画

.Net Core VS2015,无法加载 DLL 'git2-785d8c4' : The specified module could not be found.(HRESULT 异常:0x8007007E)