angular-cli icon indicating copy to clipboard operation
angular-cli copied to clipboard

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

Open zijianhuang opened this issue 8 years ago • 31 comments

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.

zijianhuang avatar Feb 02 '18 23:02 zijianhuang

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.

umarov avatar Feb 03 '18 17:02 umarov

I have the same problem.

snajperek130 avatar Feb 04 '18 10:02 snajperek130

I too have the same issue.

softsaravanacse avatar Feb 05 '18 10:02 softsaravanacse

Same here.

JustSomeHack avatar Feb 06 '18 01:02 JustSomeHack

I have the same problem.

tsuyoshi-nishikawa avatar Feb 06 '18 05:02 tsuyoshi-nishikawa

Same issue here, resolved by using es5 as target.

johan-- avatar Feb 15 '18 07:02 johan--

Same.

rujorgensen avatar Feb 16 '18 13:02 rujorgensen

Same issue here with https://github.com/coryrylan/ng-pokedex

coryrylan avatar Feb 18 '18 03:02 coryrylan

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"

jameskentTX avatar Feb 18 '18 13:02 jameskentTX

Same issue :(

dnemoga avatar Feb 19 '18 15:02 dnemoga

Same Issue CLI: 1.7.0 Typescript: 2.5.3, 2.6.2, 2.7.1

kennyrulez avatar Feb 19 '18 16:02 kennyrulez

Same Issue. HttpClient seems to be the trigger. Targeting es5 seems to fix the issue but you must change it in the tsconfig.app.json file as well as the tsconfig.json file in the root.

dldavis avatar Feb 19 '18 16:02 dldavis

Ditto. Same error after upgrading CLI to 1.7.0. Switching from es6 to es5 target appears to fix the problem.

TimUnderhay avatar Feb 20 '18 20:02 TimUnderhay

This is happening with CLI 1.6.8 also, so not sure that it is limited to 1.7.0.

henetiriki avatar Feb 20 '18 20:02 henetiriki

This issue is stopping es2015 from becoming popular. Currently I have 2 NG2+ projects: project A needs to support IE which dose not support es2015, and project B is LOB which has no need to support IE. The 2nd one should had enjoyed es2015 without polyfill. Project B used to be working well with es2015 with SystemJS. Now with NG Cli I had to reverse back to es5.

zijianhuang avatar Feb 20 '18 21:02 zijianhuang

Facing the same issue. This became a showstopper for me. Please suggest a fix for this issue ASAP.

Vishnu407 avatar Feb 21 '18 10:02 Vishnu407

For me targeting es5 in tsconfig.json rather than es6 solved the issue. "target": "es5", in tsconfig.json

Vishnu407 avatar Feb 21 '18 11:02 Vishnu407

As of CLI 1.7.1 and the Angular 5.2.6, the problem still persists.

zijianhuang avatar Feb 22 '18 07:02 zijianhuang

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

Marabyte avatar Feb 26 '18 14:02 Marabyte

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

kdcro101 avatar Feb 27 '18 17:02 kdcro101