【问题标题】:main.ts and polyfills.ts is missing from the Typescript compilation during upgrade to Angular 9在升级到 Angular 9 期间,Typescript 编译中缺少 main.ts 和 polyfills.ts
【发布时间】:2021-02-03 08:08:11
【问题描述】:

我正在尝试将 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 从 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 上有一些类似的主题,但似乎没有一个答案适合我的情况。我已将 ""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"]
}

【问题讨论】:

    标签: angular asp.net-core webpack


    【解决方案1】:

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

    因此,在 tsconfig.app.json 中不应有:""files": ["main.ts", "polyfills.ts"]" 它应该在 tsconfig.json 中(但以 src/ 开头)

    【讨论】:

    • 它适用于我没有src/ 前缀。谢谢
    猜你喜欢
    • 2018-08-12
    • 2020-12-02
    • 2021-02-12
    • 2020-05-27
    • 2018-11-23
    • 2019-07-05
    • 2020-10-06
    • 2019-01-05
    • 1970-01-01
    相关资源
    最近更新 更多