Angular 构建 - 索引 html 生成失败。未定义:9:219187:属性缺少“:”

Max*_*xim 2 node.js angular-cli ng-build

我有一个 Angular 应用程序,它似乎不是使用产品配置构建的。我收到以下错误:

 Index html generation failed.
 undefined:9:219187: property missing ':'
 npm ERR! code ELIFECYCLE
 npm ERR! errno 1
 npm ERR! JI.Infopool.WebApp@0.0.0 build: `ng build --outputHashing=all "--configuration=prod"`
 npm ERR! Exit status 1
 npm ERR!
 npm ERR! Failed at the JI.Infopool.WebApp@0.0.0 build script.
 npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
Run Code Online (Sandbox Code Playgroud)

正常的构建工作正常,我认为我没有更改任何运行配置。我在日志文件中也找不到任何有用的内容。这是 angular.json 文件中的配置:

"prod": {
          "baseHref": "/myApp/",
          "optimization": true,
          "outputHashing": "all",
          "sourceMap": false,
          "namedChunks": false,
          "aot": true,
          "extractLicenses": true,
          "vendorChunk": false,
          "buildOptimizer": true,
          "fileReplacements": [
            {
              "replace": "src/environments/environment.ts",
              "with": "src/environments/environment.prod.ts"
            }
          ]
        },
Run Code Online (Sandbox Code Playgroud)

Hil*_*sis 5

只需像这样更改“angular.json”文件:

      "configurations": {
            "production": { // <=
              "optimization": { //<= add this 
                "scripts": true, 
                "styles": { 
                 "minify": true, 
                 "inlineCritical": false 
                }
               },
              "budgets": [...]
Run Code Online (Sandbox Code Playgroud)