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

An unhandled exception while Generating ES5 bundles

Open ronfogel opened this issue 7 years ago • 85 comments

🐞 Bug report

Command (mark with an x)

- [ ] new
- [x ] build
- [ ] serve
- [ ] test
- [ ] e2e
- [ ] generate
- [ ] add
- [ ] update
- [ ] lint
- [ ] xi18n
- [ ] run
- [ ] config
- [ ] help
- [ ] version
- [ ] doc

Is this a regression?

Yes, the previous version in which this bug was not present was 8.2.1, maybe 8.2.2

Description

When using ng build in circle ci, it throws an error (screenshot attached):

Generating ES5 bundles for differential loading...
An unhandled exception occurred: cancel after 1 retries!
Screen Shot 2019-08-31 at 12 42 29

🔬 Minimal Reproduction

Unfortunately, I cant provide a way to reproduce it as it happens only in CI and I am unable to get the logs. I think it's related to the size of my app but I cant be sure.

🔥 Exception or Error


WARNING in budgets, maximum exceeded for initial. Budget 2 MB was exceeded by 2.2 MB.
Generating ES5 bundles for differential loading...
An unhandled exception occurred: cancel after 1 retries!
See "/tmp/ng-8Tr7C1/angular-errors.log" for further details.
npm ERR! file sh
npm ERR! code ELIFECYCLE
npm ERR! errno ENOENT
npm ERR! syscall spawn
npm ERR! [email protected] build-dev: `ng build --configuration dev`
npm ERR! spawn ENOENT
npm ERR! 
npm ERR! Failed at the [email protected] build-dev script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     /home/circleci/.npm/_logs/2019-08-31T09_20_07_881Z-debug.log
Exited with code 1

🌍 Your Environment


@angular-devkit/architect         0.803.2
@angular-devkit/build-angular     0.803.2
@angular-devkit/build-optimizer   0.803.2
@angular-devkit/build-webpack     0.803.2
@angular-devkit/core              8.3.2
@angular-devkit/schematics        8.3.2
@angular/cdk                      8.1.4
@angular/cli                      8.3.2
@angular/flex-layout              8.0.0-beta.27
@angular/material                 8.1.4
@ngtools/webpack                  8.3.2
@schematics/angular               8.3.2
@schematics/update                0.803.2
rxjs                              6.5.2
typescript                        3.5.3
webpack                           4.39.2

ronfogel avatar Aug 31 '19 09:08 ronfogel

The number of affected users seems to be quite high, in the end. Any news from the dev team ? Have you been able to precisely identify the issue ?

xawill avatar Sep 26 '19 11:09 xawill

This seems to be resolved for me using the latest CLI.

josh-m-sharpe avatar Sep 26 '19 13:09 josh-m-sharpe

I have updated to the latest Angular 8 (8.2.8) and CLI (8.3.6) versions with compilerOptions / target:'es2015' but unfortunately I still get the same heap error. I have to set target back to es5 to make it work.

Although, I have tried it with my existing project and not a new one. I will check if the new CLI changed anything in the config files I need to adjust in my existing config.

csegyud avatar Sep 26 '19 14:09 csegyud

For this issue, the @angular-devkit/build-angular package is the critical element. Ensure that it is at the latest version (currently 0.803.6).

Please also try to keep this issue centered on the originating issue of memory usage. Other issues should be tracked separately and may already be in the process of being fixed (#15666).

clydin avatar Sep 26 '19 14:09 clydin

I take back my previous comment that this has been fixed. I am still seeing the issue using these packages:

    "@angular/common": "~8.2.8",
    "@angular/core": "~8.2.8",
    "@angular/forms": "~8.2.8",
    "@angular/platform-browser": "~8.2.8",
    "@angular/platform-browser-dynamic": "~8.2.8",
    "@angular/router": "~8.2.8",
    "@angular-devkit/architect": "^0.803.6",
    "@angular-devkit/build-angular": "^0.803.6",
    "@angular-devkit/core": "^8.3.6",
    "@angular-devkit/schematics": "^8.3.6",
    "@angular/cli": "^8.3.6",
    "@angular/compiler": "^8.2.8",
    "@angular/compiler-cli": "^8.2.8",
    "@angular/language-service": "^8.2.8",

Error:

Generating ES5 bundles for differential loading...
An unhandled exception occurred: cancel after 1 retries!

josh-m-sharpe avatar Sep 26 '19 15:09 josh-m-sharpe

Got the same error with the local build inside docker container. Updating packages didn't help. Switching target to es5 solve issue.

andrexx avatar Sep 26 '19 18:09 andrexx

Same issue with the worker-related exception only occurring when using CI (AWS CodeBuild) versus manually building on my local computer. Bumped the CodeBuild environment from 3GB RAM/2vCPU to 7GB RAM/4vCPU, and that resolved the error.

JDeVri01 avatar Oct 02 '19 01:10 JDeVri01

Experiencing the same issue. Only solution is to not generate bundles for differential loading as described above ☝️https://github.com/angular/angular-cli/issues/15493#issuecomment-529098088

petersandor avatar Oct 02 '19 11:10 petersandor

Try with this: node_modules/@angular/cli/bin/ng build --prod or: node --max_old_space_size=8192 node_modules/@angular/cli/bin/ng build --prod

krzysiek3d avatar Oct 02 '19 12:10 krzysiek3d

Same here:

An unhandled exception occurred: Call retries were exceeded
See "/private/var/folders/ms/qq0y5v_d0_q8q1sk43c87b080000gn/T/ng-xZOLD0/angular-errors.log" for further details.

event": "Allocation failed - JavaScript heap out of memory",
    "trigger": "FatalError",

jimmykane avatar Oct 03 '19 13:10 jimmykane

If it helps this solved it for me:

"build-beta": "NODE_OPTIONS=--max-old-space-size=8192 ng build --verbose --configuration beta",

prepending to the scripts part of your app build the

NODE_OPTIONS=--max-old-space-size=8192

Should increase memory size for those that this can help them

jimmykane avatar Oct 03 '19 13:10 jimmykane

For anyone experiencing the memory issue, please ensure that the CLI is on the latest version (currently 8.3.7). Also, please ensure that the @angular-devkit/build-angular package is also at the latest (currently 0.803.7). There are also benefits to using the current version of Node.js (12.11) if possible.

For the team to provide more assistance and troubleshoot these occurrences, please provide additional information regarding your projects. An example repository that can consistently reproduce the behavior would be ideal. However, the settings used during the build are paramount (especially optimization, aot, and sourcemaps). An output of a working ES5 only build with size information would also be beneficial.

clydin avatar Oct 03 '19 16:10 clydin

@clydin here is a repo https://github.com/jimmykane/quantified-self/ you can try to do a beta build and it will fail

jimmykane avatar Oct 04 '19 10:10 jimmykane

Upgraded our app from 7 to 8 and ran into this today. @jimmykane solved my issue by increasing the max old space size flag.

NODE_OPTIONS=--max-old-space-size=8192 ng build --prod

Our build right now is pretty large. The largest file that is built is the main-es5.xxxx.js file at 6.2MB.

richarddavenport avatar Oct 04 '19 17:10 richarddavenport

@richarddavenport , I can also confirm that the NODE_OPTIONS solution from @jimmykane is working, and in appr. 3 minutes it builds without errors. Peak memory usage exceeds 4 GB. Not too fast though on an Core i7 / 32GB / SSD machine.

And I can also see that my es5 bundle is 14MB while the es2015 bundle is 17MB. Although the polyfill for es2015 is 460KB less than es5 polyfill, the bundle size is much much more than I can save on the polyfill files. So I have a feeling that it is not mature yet - while the idea sounds really good.

csegyud avatar Oct 04 '19 18:10 csegyud

@csegyud Are those numbers the on-disk sizes? The ES5 bundles are essentially the ES2015 bundles with additional code structures added to mimic ES2015 features in ES5. In development mode, large ES5 bundles are also not pretty-printed after transformation whereas the ES2015 bundles are left as-is. This can give the illusion that the ES5 bundles are smaller when optimizations are not enabled.

clydin avatar Oct 04 '19 19:10 clydin

Faced with same issues after migration from Angular 7 to 8.

  1. error with CI build: "javascript heap out of memory" Fixed via --max-old-space-size=4096
  2. error with local build inside Docker for Windows container: "Call retries were exceeded" Fixed via allocating 4Gb of memory to Docker engine (it was 2Gb by default in docker settings).

mogwai1 avatar Oct 06 '19 11:10 mogwai1

@clydin, These are on disk sizes and result of a production build.

The sizes of *.js in my dist folder:

17720682 bytes main-es2015.c54c6ee19c4c250f0f9a.js
14716590 bytes main-es5.c54c6ee19c4c250f0f9a.js
  132733 bytes polyfills-es2015.833fec98dca74639f6a6.js
  605953 bytes polyfills-es5.12a64184cfbc85c720a9.js
    6263 bytes runtime-es2015.d6c52737d4587c65265f.js
    5606 bytes runtime-es5.d6c52737d4587c65265f.js

csegyud avatar Oct 06 '19 13:10 csegyud

Are you sure the project has optimizations enabled? The polyfill sizes for a new application in production are as follows:

37,293   polyfills-es2015.f80ea2f8856ba3d344c6.js
126,094  polyfills-es5.1323fe914a6541b59b65.js

And for a development (with AOT) build:

132,713  polyfills-es2015.js
636,519  polyfills-es5.js

Regardless, the issue appears to be triggered by having a javascript file that is in the 10MB+ range. Work is ongoing to remedy the situation and the team will update as progress is made.

clydin avatar Oct 07 '19 00:10 clydin

@clydin, sure, you were right, the optimization was turned off. Turning it on I get 5MB bundles for both versions (es2015 is smaller by a 200 KB) which is correct enough. BTW, the compilation took ~5:30 minutes now and the memory usage peaked almost 6 GB. :) No problem though, it just fits the budget (32GB). Thanks for the hint.

csegyud avatar Oct 07 '19 11:10 csegyud