用于生产的 Angular 构建失败 [英] Angular build for production fails

查看:33
本文介绍了用于生产的 Angular 构建失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我尝试使用以下命令为生产构建我的 angular 应用程序 ng build --prod --build-optimizer 我得到以下输出:

When I try to build for production my angular application with the following command ng build --prod --build-optimizer I get the following output:

Date: 2019-01-29T08:39:12.193Z
Hash: 05648c76cf91b1245f68
Time: 27920ms
chunk {0} runtime.1eee2a92f0ed121267d0.js (runtime) 2.22 kB [entry] [rendered]
chunk {1} 1.71c6b320e46d84e7f880.js () 88.8 kB  [rendered]
chunk {2} main.058aa675d38205a01c2e.js (main) 1.65 MB [initial] [rendered]
chunk {3} polyfills.6226af78bf8dfb509e3e.js (polyfills) 61.7 kB [initial] [rendered]
chunk {4} styles.dec6a5db702d518085c9.css (styles) 61.2 kB [initial] [rendered]
chunk {5} 5.639dab8d0d9c763ecce1.js () 639 kB  [rendered]
chunk {6} 6.eeb0ec1b5f6ee2bc4225.js () 130 kB  [rendered]

ERROR in 5.639dab8d0d9c763ecce1.js from Terser
--> Unexpected token: punc ()) [5.639dab8d0d9c763ecce1.js:4086,34] <--
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! second-frontend@0.0.0 build_prod: `ng build --prod --build-optimizer`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the second-frontend@0.0.0 build_prod script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

为开发而构建并为应用程序提供服务运行良好,所以我怀疑这可能与 uglify 过程有关.用于生产的angular json配置如下:

Building for development and serve the application works fine so I suspect it might be related to the uglify process. The angular json configuration for production is as follows:

"production": {
  "fileReplacements": [
    {
      "replace": "src/environments/environment.ts",
      "with": "src/environments/environment.prod.ts"
    }
  ],
  "optimization": true,
  "outputHashing": "all",
  "sourceMap": false,
  "extractCss": true,
  "namedChunks": false,
  "aot": true,
  "extractLicenses": true,
  "vendorChunk": false,
  "buildOptimizer": true
},

和角度版本和包是:

Angular CLI: 7.2.3
Node: 11.1.0
OS: win32 x64
Angular: 7.2.0
... animations, common, compiler, compiler-cli, core, forms
... http, language-service, platform-browser
... platform-browser-dynamic, router

Package                           Version
-----------------------------------------------------------
@angular-devkit/architect         0.12.1
@angular-devkit/build-angular     0.12.1
@angular-devkit/build-optimizer   0.12.1
@angular-devkit/build-webpack     0.12.1
@angular-devkit/core              7.2.1
@angular-devkit/schematics        7.2.3
@angular/cdk                      7.2.1
@angular/cli                      7.2.3
@angular/flex-layout              7.0.0-beta.23
@angular/material                 7.2.1
@ngtools/webpack                  7.2.1
@schematics/angular               7.2.3
@schematics/update                0.12.3
rxjs                              6.3.3
typescript                        3.2.2
webpack                           4.23.1

最后,tsconfig.json文件有如下内容:

finally, the tsconfig.json file has the following content:

{
  "compileOnSave": false,
  "compilerOptions": {
    "baseUrl": "./",
    "paths": {
      "@app/*": ["src/app/*"],
      "@env/*": ["src/environments/*"]
    },
    "outDir": "./dist/out-tsc",
    "sourceMap": true,
    "declaration": false,
    "moduleResolution": "node",
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "target": "es5",
    "typeRoots": [
      "node_modules/@types"
    ],
    "lib": [
      "es2017",
      "dom"
    ]
  }
}

如果我将 angular.json "SourceMap" 选项从 false 更改为 true 并尝试执行它构建的生产构建而不会抛出任何错误:

If I change angular.json "SourceMap" option from false to true and try to execute the production build it builds without throwing any error:

Date: 2019-01-29T08:47:50.705Z
Hash: 369c42b07abe57a96302
Time: 42331ms
chunk {0} runtime.90bf2a53d53699d5ef63.js, runtime.90bf2a53d53699d5ef63.js.map (runtime) 2.28 kB [entry] [rendered]
chunk {1} 1.9ac663afcd9a15f9ad98.js, 1.9ac663afcd9a15f9ad98.js.map () 88.9 kB  [rendered]
chunk {2} main.e3c4184e7cbc49903adc.js, main.e3c4184e7cbc49903adc.js.map (main) 1.65 MB [initial] [rendered]
chunk {3} polyfills.6c3e7ecffd41b4bb0d68.js, polyfills.6c3e7ecffd41b4bb0d68.js.map (polyfills) 61.7 kB [initial] [rendered]
chunk {4} styles.cb7c8ca5b54a30c69879.css, styles.cb7c8ca5b54a30c69879.css.map (styles) 61.2 kB [initial] [rendered]
chunk {5} 5.72034e2cb610bc9b5476.js, 5.72034e2cb610bc9b5476.js.map () 251 kB  [rendered]
chunk {6} 6.45111c2fd642148bbdd3.js, 6.45111c2fd642148bbdd3.js.map () 131 kB  [rendered]

Process finished with exit code 0

有什么建议吗?


运行 ng build --prod --optimization=false 编译完美

推荐答案

正如 Anton Mitsev 所述,问题是一个拖尾昏迷.删除尾随后,错误消失.

As Anton Mitsev stated, the problem was a trailing coma. When removing the trailing the error disappears.

这篇关于用于生产的 Angular 构建失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆