无法进行 ng build 优化,出现 Angular 错误

4

我正在使用Angular 13构建实时聊天应用,我尝试构建我的Angular应用程序,以便在我的Node.js web服务器上进行测试,但每次尝试时:

ng build

我在控制台中得到以下错误:enter image description here

我确实尝试删除错误消息显示的文件,但总是出现新文件,我认为这可能是生产环境的错误配置,但是它是默认配置,所以我不知道发生了什么 ://

package.json:

{
  "name": "chat-app",
  "version": "0.0.0",
  "scripts": {
    "ng": "ng",
    "start": "ng serve",
    "build": "ng build",
    "watch": "ng build --watch --configuration development",
    "test": "ng test"
  },
  "private": true,
  "dependencies": {
    "@angular/animations": "~13.1.0",
    "@angular/common": "~13.1.0",
    "@angular/compiler": "~13.1.0",
    "@angular/core": "~13.1.0",
    "@angular/forms": "~13.1.0",
    "@angular/platform-browser": "~13.1.0",
    "@angular/platform-browser-dynamic": "~13.1.0",
    "@angular/router": "~13.1.0",
    "@auth0/auth0-angular": "^1.8.2",
    "bulma": "^0.9.3",
    "moment": "^2.29.1",
    "normalize": "^0.3.1",
    "normalize.css": "^8.0.1",
    "rxjs": "~7.4.0",
    "tslib": "^2.3.0",
    "uuid": "^8.3.2",
    "zone.js": "~0.11.4"
  },
  "devDependencies": {
    "@angular-devkit/build-angular": "~13.1.3",
    "@angular/cli": "~13.1.3",
    "@angular/compiler-cli": "~13.1.0",
    "@types/jasmine": "~3.10.0",
    "@types/node": "^12.11.1",
    "jasmine-core": "~3.10.0",
    "karma": "~6.3.0",
    "karma-chrome-launcher": "~3.1.0",
    "karma-coverage": "~2.1.0",
    "karma-jasmine": "~4.0.0",
    "karma-jasmine-html-reporter": "~1.7.0",
    "typescript": "~4.5.2"
  }
}

angular.json:

{
  "$schema": "./node_modules/@angular/cli/lib/config/schema.json",
  "cli": {
    "analytics": "6cff9a4a-d15f-4597-ad7a-d59e9b658bf9"
  },
  "version": 1,
  "newProjectRoot": "projects",
  "projects": {
    "ChatApp": {
      "projectType": "application",
      "schematics": {
        "@schematics/angular:component": {
          "style": "scss"
        },
        "@schematics/angular:application": {
          "strict": true
        }
      },
      "root": "",
      "sourceRoot": "src",
      "prefix": "app",
      "architect": {
        "build": {
          "builder": "@angular-devkit/build-angular:browser",
          "options": {
            "outputPath": "dist/chat-app",
            "index": "src/index.html",
            "main": "src/main.ts",
            "polyfills": "src/polyfills.ts",
            "tsConfig": "tsconfig.app.json",
            "inlineStyleLanguage": "scss",
            "assets": [
              "src/favicon.ico",
              "src/assets"
            ],
            "styles": [
              "src/styles.scss"
            ],
            "scripts": []
          },
          "configurations": {
            "production": {
              "budgets": [
                {
                  "type": "initial",
                  "maximumWarning": "4mb",
                  "maximumError": "5mb"
                },
                {
                  "type": "anyComponentStyle",
                  "maximumWarning": "4mb",
                  "maximumError": "5mb"
                }
              ],
              "fileReplacements": [
                {
                  "replace": "src/environments/environment.ts",
                  "with": "src/environments/environment.prod.ts"
                }
              ],
              "outputHashing": "all"
            },
            "development": {
              "buildOptimizer": true,
              "optimization": true,
              "vendorChunk": true,
              "extractLicenses": false,
              "sourceMap": true,
              "namedChunks": true
            }
          },
          "defaultConfiguration": "production"
        },
        "serve": {
          "builder": "@angular-devkit/build-angular:dev-server",
          "configurations": {
            "production": {
              "browserTarget": "ChatApp:build:production"
            },
            "development": {
              "browserTarget": "ChatApp:build:development"
            }
          },
          "defaultConfiguration": "development"
        },
        "extract-i18n": {
          "builder": "@angular-devkit/build-angular:extract-i18n",
          "options": {
            "browserTarget": "ChatApp:build"
          }
        },
        "test": {
          "builder": "@angular-devkit/build-angular:karma",
          "options": {
            "main": "src/test.ts",
            "polyfills": "src/polyfills.ts",
            "tsConfig": "tsconfig.spec.json",
            "karmaConfig": "karma.conf.js",
            "inlineStyleLanguage": "scss",
            "assets": [
              "src/favicon.ico",
              "src/assets"
            ],
            "styles": [
              "src/styles.scss"
            ],
            "scripts": []
          }
        }
      }
    }
  },
  "defaultProject": "ChatApp"
}

I hope someone can help me to understand why this happen, thanks, have a nice day.


这个问题可能类似...用户有一个 angular.json 配置的示例,可以防止优化错误,可能会有所帮助 https://dev59.com/kFEG5IYBdhLWcg3wMGPV - undefined
2个回答

0

我遇到了类似的问题, 错误:优化错误 [main.64ac3ee7acfe838b.js]:错误:服务已停止 我在使用命令“bg build --output-path docs --base-href /”运行 Angular 构建时遇到了上述错误。

在添加上述解决方案后,问题最终得到解决。

注意:将配置添加到 architect 部分,而不是 serve 部分 ....... "architect": { "build": { "builder": "@angular-devkit/build-angular:browser", "options": { "outputPath": "dist/my-portfolio", "index": "src/index.html", "main": "src/main.ts", "polyfills": [ "zone.js" ], "tsConfig": "tsconfig.app.json", "assets": [ "src/favicon.ico", "src/assets" ], "styles": [ "src/styles.css" ], "scripts": [] }, "configurations": { "production": { "optimization": false, "budgets": [ { "type": "initial", "maximumWarning": "2mb", "maximumError": "5mb" }, .......


-4

angular.json的生产环境中添加这段代码。

...
"configurations": {
   "production": {
      "optimization": false,
...
}
...

1
"configurations": { "production": { "optimization": false, .... } ...“配置”:{“生产”:{“优化”:false,....} ... - undefined
请使用代码格式来编写代码 - undefined
1
对于大多数人来说,在生产中关闭优化并不是一个可行的答案。 - undefined

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接