Solvedangular starter ERROR with UglifyJs when building npm start build:prod

Note: for support questions, please use one of these channels: Chat: AngularClass.slack or Twitter: @AngularClass

  • I'm submitting a ...
    [x] bug report
    [ ] feature request
    [ ] question about the decisions made in the repository
  • Do you want to request a feature or report a bug?
    Uglify gives an ERROR when running npm run build:prod
    `
    ERROR in 1.87152edfeeca0e76c2dd.chunk.js from UglifyJs
    SyntaxError: Unexpected token: name (Detail) [./~/angular2-template-loader!./src/app/+detail/detail.component.ts:13,0]

ERROR in 2.d14d91212c6668d117ed.chunk.js from UglifyJs
SyntaxError: Unexpected token: name (About) [./~/angular2-template-loader!./src/app/about/about.component.ts:29,0]

ERROR in main.7ef34497f05b466f628b.bundle.js from UglifyJs
SyntaxError: Unexpected token: name (App) [./~/angular2-template-loader!./src/app/app.component.ts:61,0]
`

npm run build:dev works fine and the only file I've changed is tsconfig.json with target: "es6" because of another bug

  • What is the current behavior?
    Can't uglify the main.bundle.js
  • If the current behavior is a bug, please provide the steps to reproduce and if possible a minimal demo of the problem via
    https://plnkr.co or similar (you can use this template as a starting point: http://plnkr.co/edit/tpl:AvJOMERrnz94ekVua0u5).
    I changed the tsconfig.json - target: "es6" because it's not recognizing "Set" and others es6 then I did a npm run build:prod :
    `
    ERROR in 1.87152edfeeca0e76c2dd.chunk.js from UglifyJs
    SyntaxError: Unexpected token: name (Detail) [./~/angular2-template-loader!./src/app/+detail/detail.component.ts:13,0]

ERROR in 2.d14d91212c6668d117ed.chunk.js from UglifyJs
SyntaxError: Unexpected token: name (About) [./~/angular2-template-loader!./src/app/about/about.component.ts:29,0]

ERROR in main.7ef34497f05b466f628b.bundle.js from UglifyJs
SyntaxError: Unexpected token: name (App) [./~/angular2-template-loader!./src/app/app.component.ts:61,0]
`

  • What is the expected behavior?
    To uglify the main.[hash].bundle.js
  • What is the motivation / use case for changing the behavior?
  • Please tell us about your environment:
    Mac OS X El Capitan
  • Angular version: 2.0.0-beta.X
  • Browser: [all | Chrome XX | Firefox XX | IE XX | Safari XX | Mobile Chrome XX | Android X.X Web Browser | iOS XX Safari | iOS XX UIWebView | iOS XX WKWebView ]
  • Other information (e.g. detailed explanation, stacktraces, related issues, suggestions how to fix, links for us to have context, eg. stackoverflow, gitter, etc)
14 Answers

✔️Accepted Answer

UglifyJsPlugin only supports es5 now, so change file tsconfig.json like below:

{
  "compilerOptions": {
    "target": "es5",
    "lib": ["dom", "es6"]
  }
}

this config will make build program solve this problem like SyntaxError: Unexpected token: name (App) ,and also be able to recognize "Set" and others es6.

Other Answers:

I can reproduce this as well.

More Issues: