Repository navigation
Description
I'm submitting a...
[ ] Regression (a behavior that used to work and stopped working in a new release)
[X] Bug report
[ ] Feature request
[ ] Documentation issue or request
[ ] Support request => Please do not submit support request here, instead see https://github.com/angular/angular/blob/master/CONTRIBUTING.md#question
Current behavior
The bundle for production environment is outputting the following invalid code, when using the HttpClientModule
return new ue.a(t=>{
const n = this.xhrFactory.build();
if (n.open(e.method, e.urlWithParams),
e.withCredentials && (n.withCredentials = !0),
e.headers.forEach((e,t)=>n.setRequestHeader(e, t.join(","))),
e.headers.has("Accept") || n.setRequestHeader("Accept", "application/json, text/plain, */*"),
!e.headers.has("Content-Type")) {
const t = e.detectContentTypeHeader();
null !== t && n.setRequestHeader("Content-Type", t)
}
if (e.responseType) {
const t = e.responseType.toLowerCase();
n.responseType = "json" !== t ? t : "text"
}
const r = e.serializeBody();
let s = null;
const o = ()=>{
if (null !== s)
return s;
const t = 1223 === n.status ? 204 : n.status
, r = n.statusText || "OK"
, o = new zo(n.getAllResponseHeaders())
, i = ("responseURL"in (n = n) && n.responseURL ? n.responseURL : /^X-Request-URL:/m.test(n.getAllResponseHeaders()) ? n.getResponseHeader("X-Request-URL") : null) || e.url;
return s = new ei({
headers: o,
status: t,
statusText: r,
url: i
})
}
Especifically the error is in this line:
, i = ("responseURL"in (n = n) && n.responseURL ? n.responseURL : /^X-Request-URL:/m.test(n.getAllResponseHeaders()) ? n.getResponseHeader("X-Request-URL") : null) || e.url;
Because in the above lines the n was declared as constant: const n = this.xhrFactory.build();
Producing the following error in chrome:
ERROR TypeError: Assignment to constant variable.
at o (main.afd9c695ba9c5bcbf50d.bundle.js:formatted:13612)
at XMLHttpRequest.i (main.afd9c695ba9c5bcbf50d.bundle.js:formatted:13621)
at e.invokeTask (polyfills.d14582d1423c077d31d1.bundle.js:1)
at Object.onInvokeTask (main.afd9c695ba9c5bcbf50d.bundle.js:formatted:1694)
at e.invokeTask (polyfills.d14582d1423c077d31d1.bundle.js:1)
at t.runTask (polyfills.d14582d1423c077d31d1.bundle.js:1)
at t.invokeTask [as invoke] (polyfills.d14582d1423c077d31d1.bundle.js:1)
at _ (polyfills.d14582d1423c077d31d1.bundle.js:1)
at XMLHttpRequest.k (polyfills.d14582d1423c077d31d1.bundle.js:1)
Similar in firefox:
ERROR
TypeError: invalid assignment to const `n'
Stack trace:
o@http://localhost:4201/main.afd9c695ba9c5bcbf50d.bundle.js:1:298093
i@http://localhost:4201/main.afd9c695ba9c5bcbf50d.bundle.js:1:298355
eFQL/</</</c</e.prototype.invokeTask@http://localhost:4201/polyfills.d14582d1423c077d31d1.bundle.js:1:22948
onInvokeTask@http://localhost:4201/main.afd9c695ba9c5bcbf50d.bundle.js:1:27946
eFQL/</</</c</e.prototype.invokeTask@http://localhost:4201/polyfills.d14582d1423c077d31d1.bundle.js:1:22861
eFQL/</</</o</t.prototype.runTask@http://localhost:4201/polyfills.d14582d1423c077d31d1.bundle.js:1:18118
eFQL/</</</u</t.invokeTask@http://localhost:4201/polyfills.d14582d1423c077d31d1.bundle.js:1:24042
_@http://localhost:4201/polyfills.d14582d1423c077d31d1.bundle.js:1:34743
k@http://localhost:4201/polyfills.d14582d1423c077d31d1.bundle.js:1:34975
Expected behavior
A valid code should be outputted when targeting ES6 for production
Minimal reproduction of the problem with instructions
Given the downloadable example at the HTTP chapter of the Tour of heroes tutorial (https://angular.io/generated/zips/toh-pt6/toh-pt6.zip)
- Disable
HttpClientInMemoryWebApiModuleandHttpClientInMemoryWebApiModuleinsrc/app/app.module.ts, so the app try to make an actual XhttpRequest - Change the target to
"target": "es6",intsconfig.json - Run the app like:
ng serve --prod
What is the motivation / use case for changing the behavior?
The output from the compilation for ES6 is broken
Environment
Angular version: 5.0.0 and 5.2.2
Browser:
- [X] Chrome (desktop) version XX
- [ ] Chrome (Android) version XX
- [ ] Chrome (iOS) version XX
- [X] Firefox version XX
- [ ] Safari (desktop) version XX
- [ ] Safari (iOS) version XX
- [ ] IE version XX
- [ ] Edge version XX
For Tooling issues:
- Node version: 8.9.1
- Platform: Mac
Others:
Worth noting this issue arises only with these three factors combined:
- Use of
HttpClientModule - Target = es6
- Building/serving with
prod
Probably this is an issue that should be fixed in the angular-cli or uglify-webpack-plugin level, but I had no time to dig deeper.
Activity
ethanpollitt commentedon Feb 1, 2018
Just ran into this issue today after migrating some code to use common/http, with references to old http in another part of the project (hence HttpModule and HttpClientModule both being imported).
Temporarily solved by reverting usage of common/http.
zijianhuang commentedon Feb 2, 2018
Me 2. I have a complex business app, and a simple heros app both with HttpClient.
With "ng build" and "ng build --aot", the apps are working fine.
With "ng build --prod", the complex business app starts fine with the login screeen, however, when making the first HttpClient call for auth, the browser console will give:
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 http call for auth is actually successful.
with "ng build --prod --no-aot", the complex business app could not start properly, with error:
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)The simple heros app has similar problem with prod.
For now, I just use "ng build --aot" for production deployment.
You may find the simple heros demo app at https://github.com/zijianhuang/webapiclientgen, and locate DemoNGCli.
Stacks:
NG 5.2.2
NG Cli 1.6.6 or 1.6.7
SelfishLucho commentedon Feb 2, 2018
I just ran into the same problem but with target:ES2015
zijianhuang commentedon Feb 2, 2018
(cont.)
when target:es5, things become fine. I just tried this in 2 NG2+ apps. So apparently ng build --prod is having some problem with target es2015.
slanden commentedon Feb 8, 2018
I'm having the same problem as zijianhuang with a login and auth call in my app targeting es2015. except when using the command "ng build -prod -sourcemaps" the error reads
ERROR TypeError: Assignment to constant variable. at u (http.js.pre-build-optimizer.js:1649) at XMLHttpRequest.i (http.js.pre-build-optimizer.js:1771) at e.invokeTask (zone.js:421) at Object.onInvokeTask (core.js.pre-build-optimizer.js:3979) at e.invokeTask (zone.js:420) at t.runTask (zone.js:188) at t.invokeTask [as invoke] (zone.js:496) at _ (zone.js:1517) at XMLHttpRequest.k (zone.js:1543)the line where it breaks in that file reads
function defaultErrorLogger(console, ...values) { (/** @type {?} */ (console.error))(...values);zijianhuang commentedon Feb 8, 2018
At this stage, I am not entire sure if the cause is in Angular/HttpClient or in Angular CLI. So I had reported to angular/angular-cli#9495 as well.
johan-- commentedon Feb 15, 2018
Same issue here, resolved by using es5 as target.
MariuszHenn commentedon Feb 15, 2018
I had the same issue, im not sure why, but removing node_modules and sets packages as below fixed it (target es6)
jameskentTX commentedon Feb 18, 2018
I had the same problem, when target was ES2015. But app compiles and works with:
I'm using "@angular/cli": "^1.7.0", "@angular/compiler": "^5.2.5"
zijianhuang commentedon Feb 22, 2018
As of CLI 1.7.1 and the Angular 5.2.6, the problem still persists.
DcsMarcRemolt commentedon Feb 22, 2018
I use @ngtools/webpack@1.10.0 and @angular-devkit/build-optimizer@0.4.0 outside of an angular-cli project (hand written webpack config) and I can also confirm this issue. Going down to es5 fixes it.
trotyl commentedon Feb 23, 2018
You can use
conditionals: falsein uglify-escompressoption to fix it. Since it's not Angular nor Angular CLI problem, making an issue (by repro without any Angular code) to uglify-es could make it solved sooner.zijianhuang commentedon Feb 23, 2018
@trotyl, thanks for hint. However, in Angular CLI, there seems no way to to define the uglify-es option in .angular-cli.json, or through other means.
Can you give more hint?
Anyway, I will report this to uglifyJS2.
Cito commentedon Mar 2, 2018
Same problem here with Angular-CLI 1.7.2. When I set
conditionals: falsetoconst uglifyCompressOptions = { ... }innode_modules/@angular/cli/models/webpack-configs/production.js, as suggested by @trotyl, the problem disappears.zijianhuang commentedon Mar 2, 2018
Apparently the solution is that NG CLI provides such switch for es2015. It seems this issue could be closed here, while I had reported to angular/angular-cli#9495.
trotyl commentedon Mar 10, 2018
Closed by angular/angular-cli#9889
pkozlowski-opensource commentedon Jun 20, 2018
Thnx @trotyl !
angular-automatic-lock-bot commentedon Sep 13, 2019
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.