0

My Angular2 web app consists of

  • Third party plugins like jquery, pdfjs, e.t.c.
  • Has services defined!
export class WorkerService{
    constructor() {

    }
}

When I am building a Dev AOT build using angular cli, there was no problem! But when I am doing a Prod AOT build using angular cli, it gives me an error saying, "Unexpected token : name (WorkerService)". The command I used is

ng build --prod --aot

What might I be doing wrong?? I don't have a spec file related to my service, would that be a problem? Thanks.

Angular CLI version: 1.0.0-beta.25.5

enter image description here

Ram Bavireddi
  • 1,139
  • 1
  • 19
  • 43

1 Answers1

0

This is an issue with the version of UglifyJs that is bundled with angular/cli. It's a release version and can only support compiled ES5 or lower. Look into your tsconfig.app.json and see the target line, probably something like

{
  "compilerOptions": {
    ...
    "target": "es2016",
    ...
}

Change es2016, es2015, es6 or whatever you have to "es5", or create this file and add the target to it, and try building again. This worked for me but may not always work if you're using ES6 or ES2016 features that can't be transpiled back to ES5.

tsconfig.json is obsolete but some IDEs like Visual Studio Code still use and I think tsconfig.spec.json is used during building and running tests.

Sloloem
  • 1,587
  • 2
  • 15
  • 37