Angular v10 - Excessive memory consumption at build
See original GitHub issueSince upgrading to Angular 10, the build process takes an excessive amount of RAM, making it impossible to deploy on Heroku (build fails with OOM error).
For the same code, just upgraded:
- Angular 9 memory consumption at prod build: ~2 to 2.5 Gb.
- Angular 10 memory consumption at prod build: ~8 to 9 Gb.
Heroku limit is 2.5 Gb, so it fails with Angular 10.
On my local computer, with no such memory limit, the build works ok.
š bug report
Is this a regression?
Yes
Description
The memory spike seems to occur after ngcc has finished its pre-compilation steps es2015 to esm2015 and starts actual compilation of the code.
Angular Version:
_ _ ____ _ ___
/ \ _ __ __ _ _ _| | __ _ _ __ / ___| | |_ _|
/ ā³ \ | '_ \ / _` | | | | |/ _` | '__| | | | | | |
/ ___ \| | | | (_| | |_| | | (_| | | | |___| |___ | |
/_/ \_\_| |_|\__, |\__,_|_|\__,_|_| \____|_____|___|
|___/
Angular CLI: 10.0.0
Node: 14.4.0
OS: linux x64
Angular: 10.0.1
... animations, cdk, common, compiler, compiler-cli, core, forms
... language-service, localize, material, platform-browser
... platform-browser-dynamic, router
Ivy Workspace: Yes
Package Version
-----------------------------------------------------------
@angular-devkit/architect 0.1000.0
@angular-devkit/build-angular 0.1000.0
@angular-devkit/build-optimizer 0.1000.0
@angular-devkit/build-webpack 0.1000.0
@angular-devkit/core 10.0.0
@angular-devkit/schematics 10.0.0
@angular/cli 10.0.0
@angular/flex-layout 10.0.0-beta.32
@ngtools/webpack 10.0.0
@schematics/angular 10.0.0
@schematics/update 0.1000.0
rxjs 6.5.5
typescript 3.9.5
webpack 4.43.0
Issue Analytics
- State:
- Created 3 years ago
- Reactions:2
- Comments:18 (7 by maintainers)
Top Results From Across the Web
Angular Build For Production Consumes Too Much Memory
This error indicates high memory usage or a memory leak in your application. The fastest way of solving this issue is by increasing...
Read more >How can I reduce the memory usage during builds? : r/angular
My Angular app is quite simple, but during builds even using the --prod flag still results in at least 1.4GB of memory usage....
Read more >Fixing Angular Build Memory Issues - Upmostly
You should try and set it relatively high, but not enough to consume all of your memory on your machine. By default, depending...
Read more >Angular build for production consumes too much memory?
I packaged my Node.js/Angular app using Docker, and I setup a GitLab Runner for one-click deployment to deploy the changes to the liveĀ ......
Read more >Component testing scenarios - Angular
That's too much effort just to answer a few simple questions about links. This section describes two techniques for minimizing the setup. Use...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Guys, I just updated from 9.1.9 to 10.0.9 and ā¦
before everything was fine
Alright, I found the culprit., and it was not what I would have ever expected.
With the migration to Angular 10, the
.browserlistrcwas changed in a way where differential loading is no longer enabled (as none of the browsers that require ES5 are included in the browsers list). When differential loading is enabled, the CLI uses a pipeline that works a bit differently in certain areas, one of which is how it deals with asset files. With differential loading disabled, copying assets is done using thecopy-webpack-pluginwhich is currently affected by a bug thatās been fixed in webpack-contrib/copy-webpack-plugin#507, but thatās not yet been released. Without the bug fix, the plugin is invoked for each Webpack compilation, of which there are 121 in the reproduction (I donāt know why itās that many). Each of those loads ~58MB of asset files into memory, accounting for some 7 GB of memory usage š±I applied the patch in webpack-contrib/copy-webpack-plugin#507 locally and it reduces memory usage by 120 times 58 MB, bringing it down to the levels pre-upgrade.
Given that thereās no
copy-webpack-pluginrelease yet, the simplest workaround for now would be to revert the changes to the.browserlistrcfile to regain 7GB of RAM. And yes, I also find that hard to believe!Angular 9 is also affected here since angular/angular-cli#17867 (released 3 weeks ago in CLI 9.1.8), as the upgrade to v6 of
copy-webpack-pluginintroduces the regression. Itās only because the browserlist configuration triggered differential loading that it didnāt result in memory issues since 9.1.8.