Skip to content

ng build --prod results in that the running app report "TypeError: Assignment to constant variable" with target:es2015 #9495

Closed

Description

@zijianhuang

Versions

Angular CLI: 1.6.7
Node: 8.9.4
OS: win32 x64
Angular: 5.2.2
... animations, common, compiler, compiler-cli, core, forms
... language-service, platform-browser, platform-browser-dynamic
... router

@angular/cli: 1.6.7
@angular-devkit/build-optimizer: 0.0.42
@angular-devkit/core: 0.0.29
@angular-devkit/schematics: 0.0.52
@ngtools/json-schema: 1.1.0
@ngtools/webpack: 1.9.7
@schematics/angular: 0.1.17
typescript: 2.6.2
webpack: 3.10.0

The tsconfig.json defined target:es2015

package.json:

  "dependencies": {
    "@angular/animations": "^5.2.2",
    "@angular/common": "^5.2.2",
    "@angular/compiler": "^5.2.2",
    "@angular/core": "^5.2.2",
    "@angular/forms": "^5.2.2",
    "@angular/platform-browser": "^5.2.2",
    "@angular/platform-browser-dynamic": "^5.2.2",
    "@angular/router": "^5.2.2",
    "concurrently": "^3.5.1",
    "core-js": "^2.5.3",
    "rxjs": "^5.5.6",
    "zone.js": "^0.8.19"
  },
  "devDependencies": {
    "@angular/cli": "1.6.7",
    "@angular/compiler-cli": "^5.2.2",
    "@angular/language-service": "^5.2.2",
    "@types/jasmine": "~2.8.3",
    "@types/jasminewd2": "~2.0.2",
    "@types/node": "^6.0.85",
    "codelyzer": "^4.0.1",
    "jasmine-core": "~2.8.0",
    "jasmine-spec-reporter": "~4.2.1",
    "karma": "~2.0.0",
    "karma-chrome-launcher": "~2.2.0",
    "karma-coverage-istanbul-reporter": "^1.2.1",
    "karma-jasmine": "~1.1.0",
    "karma-jasmine-html-reporter": "^0.2.2",
    "protractor": "~5.1.2",
    "ts-node": "~4.1.0",
    "tslint": "~5.9.1",
    "uglifyjs-webpack-plugin": "^1.1.8",
    "typescript": "^2.6.2"
  }

Repro steps

  • Step 1

Find the simple heros demo app at https://github.com/zijianhuang/webapiclientgen, and locate DemoNGCli

or the demo app downloadable in https://angular.io/tutorial/toh-pt6

  • Step 2

Go to respective source folder and run ng build --prod

  • Step 3

Run the app with IIS, or you may try Apache or other Web server. And use Chrom or alike browse the app.

Observed behavior

The app will misbehave, with the following console traces when making the first HttpClient call.
ERROR TypeError: Assignment to constant variable. at r (main.14d23ee13c3a14c67d46.bundle.js:1) at XMLHttpRequest.a (main.14d23ee13c3a14c67d46.bundle.js:1) at e.invokeTask (polyfills.8e8e9e6cb9f95b7ba9ab.bundle.js:1) at Object.onInvokeTask (main.14d23ee13c3a14c67d46.bundle.js:1) at e.invokeTask (polyfills.8e8e9e6cb9f95b7ba9ab.bundle.js:1) at t.runTask (polyfills.8e8e9e6cb9f95b7ba9ab.bundle.js:1) at t.invokeTask [as invoke] (polyfills.8e8e9e6cb9f95b7ba9ab.bundle.js:1) at _ (polyfills.8e8e9e6cb9f95b7ba9ab.bundle.js:1) at XMLHttpRequest.k (polyfills.8e8e9e6cb9f95b7ba9ab.bundle.js:1)

The HttpClient call is actually successful with status 200 returned.

Desired behavior

Heros display.

Mention any other details that might be useful (optional)

ng build --prod --no-aot will result in similar errors:

Uncaught TypeError: Assignment to constant variable. at ih._compileModule (vendor.defd7bfff770299239f9.bundle.js:1) at j.then (vendor.defd7bfff770299239f9.bundle.js:1) at Object.then (vendor.defd7bfff770299239f9.bundle.js:1) at ih._compileModuleAndComponents (vendor.defd7bfff770299239f9.bundle.js:1) at ih.compileModuleAsync (vendor.defd7bfff770299239f9.bundle.js:1) at useClass.compileModuleAsync (vendor.defd7bfff770299239f9.bundle.js:1) at ls.bootstrapModule (vendor.defd7bfff770299239f9.bundle.js:1) at Object.cDNt (main.98d929d5770520d2cd22.bundle.js:1) at o (inline.66056c9a0e270b3547d6.bundle.js:1) at Object.0 (main.98d929d5770520d2cd22.bundle.js:1)

ng build --aot is fine.

ng build is fine.

When the tsconfig.json defined target:es5, ng build --prod results in correct behavior in runtime.

Activity

  1. changed the title [-]ng build --prod will have the running app report "TypeError: Assignment to constant variable" [/-] [+]ng build --prod results in that the running app report "TypeError: Assignment to constant variable" with target:es2015[/+] on Feb 2, 2018
  2. umarov commented on Feb 3, 2018

    @umarov

    I have the same issue. Only way is targeting ES5. I haven't gotten a chance to create a demo client to reproduce this issue. Thanks for making it.

  3. snajperek130 commented on Feb 4, 2018

    @snajperek130

    I have the same problem.

  4. softsaravanacse commented on Feb 5, 2018

    @softsaravanacse

    I too have the same issue.

  5. JustSomeHack commented on Feb 6, 2018

    @JustSomeHack

    Same here.

  6. tsuyoshi-nishikawa commented on Feb 6, 2018

    @tsuyoshi-nishikawa

    I have the same problem.

  7. johan-- commented on Feb 15, 2018

    @johan--

    Same issue here, resolved by using es5 as target.

  8. rujorgensen commented on Feb 16, 2018

    @rujorgensen

    Same.

  9. coryrylan commented on Feb 18, 2018

    @coryrylan
    Contributor
  10. jameskentTX commented on Feb 18, 2018

    @jameskentTX

    I had the same problem, when target was ES2015. But app compiles and works with:

    1. "target": "es5" - in tsconfig.json
    2. "typescript": "~2.5.3" - in package.json

    I'm using "@angular/cli": "^1.7.0", "@angular/compiler": "^5.2.5"

  11. dnemoga commented on Feb 19, 2018

    @dnemoga

    Same issue :(

  12. 8 remaining items

  13. Marabyte commented on Feb 26, 2018

    @Marabyte

    I'm seeing this issue with the HttpClientJsonpModule when compiling to es2015 with CLI 1.7 and 5.2

  14. kdcro101 commented on Feb 27, 2018

    @kdcro101

    Same here:
    ERROR TypeError: Assignment to constant variable.

    Workaround in my case is was reverting from HttpClientModule back to HttpModule.
    Build succeeds using cli 1.7.1 and es2015 target.

    I think problem is in HttpClientModule

  15. DutchKevv commented on Feb 27, 2018

    @DutchKevv

    Same here, anyone knowns a workaround?

    p.s. workaround seems to be to set tsconfig -> target : 'es5'..

    I only getting the error when compiling to > es2015

  16. TimUnderhay commented on Feb 28, 2018

    @TimUnderhay

    Just updated to the newly-released CLI 1.7.2 and Angular 5.2.7. The problem persists.

  17. DutchKevv commented on Mar 1, 2018

    @DutchKevv

    Update to Angular 6.0.0-beta.6 and same problem still there.

    Solution:

    tsconfig.json -> target: "es5"

    Any news on this from @angular ?? It makes the new httpClientModule a bit useless :(

  18. zijianhuang commented on Mar 2, 2018

    @zijianhuang
    Author

    According to mishoo/UglifyJS#2949, the cause is in UglifyJS2 which has a switch to workaround, however, NG CLI is not exposing this switch, while it is using UtlifyJS2. According to the comment by kzc, NG CLI may just provide a switch to fix the problem, or simply use that switch by default for target es2015.

  19. zijianhuang commented on Mar 2, 2018

    @zijianhuang
    Author

    In angular/angular#21948, Cito had suggested: "Same problem here with Angular-CLI 1.7.2. When I set conditionals: false to const uglifyCompressOptions = { ... } in node_modules/@angular/cli/models/webpack-configs/production.js, as suggested by @trotyl, the problem disappears."

    Hopefully Angular CLI team will provide a solution soon.

  20. wiedikerli commented on Mar 6, 2018

    @wiedikerli

    Can someone of the cli team tell us what the plan is?
    If you plan to release a hotfix or if it's on the map for the next release.

    According to mishoo/UglifyJS#2949, the cause is in UglifyJS2 which has a switch to workaround, however, NG CLI is not exposing this switch, while it is using UtlifyJS2

    This would be a quick fix, but would work for me.
    The issue is breaking my production site and I cannot change back to es5 nor switch back to HttpModule.

    Just mentioning @filipesilva 😏

  21. TimUnderhay commented on Mar 6, 2018

    @TimUnderhay

    As a workaround, I've added this to my build job, after I run npm install:

    sed -i'' 's/typeofs: false/typeofs: false, inline: 1/' node_modules/@angular/cli/models/webpack-configs/production.js

  22. tatsujb commented on Mar 9, 2018

    @tatsujb

    can confirm clydin's merge (and subsequent angular cli v. 1.7.3) fixed it. ...at least for me.

  23. BanjoBatman commented on Mar 9, 2018

    @BanjoBatman

    Can also confirm that angular cli v. 1.7.3 fixed this issue.
    Thanks everyone!

  24. clydin commented on Mar 9, 2018

    @clydin
    Member

    Closing this as resolved. If anyone is still encountering issues while using 1.7.3 within a project, please open a new issue detailing the problem.

  25. angular-automatic-lock-bot commented on Sep 8, 2019

    @angular-automatic-lock-bot

    This issue has been automatically locked due to inactivity.
    Please file a new issue if you are encountering a similar or related problem.

    Read more about our automatic conversation locking policy.

    This action has been performed automatically by a bot.

  26. locked and limited conversation to collaborators on Sep 8, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions