angular-cli: ng build fail with 'JavaScript heap out of memory' with patch 6.0.3
Versions
Angular CLI: 6.0.3
Node: 8.11.1
OS: darwin x64 (MacBook Pro 8Go RAM)
Angular: 6.0.2
... animations, common, compiler, compiler-cli, core, forms
... http, language-service, platform-browser
... platform-browser-dynamic, router, upgrade
Package Version
-----------------------------------------------------------
@angular-devkit/architect 0.6.3
@angular-devkit/build-angular 0.6.3
@angular-devkit/build-optimizer 0.6.3
@angular-devkit/core 0.6.3
@angular-devkit/schematics 0.6.3
@angular/cli 6.0.3
@ngtools/webpack 6.0.3
@schematics/angular 0.6.3
@schematics/update 0.6.3
rxjs 6.1.0
typescript 2.7.2
webpack 4.8.3
Repro steps
ng build --prod
Observed behavior
92% chunk asset optimization UglifyJSPlugin [… waiting for long time] FATAL ERROR: CALL_AND_RETRY_LAST Allocation failed - JavaScript heap out of memory
Desired behavior
Build works
Mention any other details that might be useful (optional)
Back to 6.0.1 and 0.6.1 like few days ago works. For the moment I didn’t change the default memory allocate to node.
About this issue
- Original URL
- State: closed
- Created 6 years ago
- Reactions: 24
- Comments: 55 (13 by maintainers)
I run since a few day’s also in this issue and done my workaround as follow:
It works actually fine for my usage with the default ng server/build process. I hope not to run in it soon again…
To git raid of this issue add this
"build:prod": "node --max_old_space_size=8192 node_modules/@angular/cli/bin/ng build --prod"
line to your scripts section of package.json file. It will looks likeand now run
npm run build:prod
Hi all,
Are you still seeing this with the latest versions? Does anyone have some up to date reproduction instructions that I can follow to see it too?
We have been seeing memory problem on Angular CLI 8 and work has been tracked in https://github.com/angular/angular-cli/issues/13734. I’ll close this issue in favor of that one. Please check out the comments there, especially https://github.com/angular/angular-cli/issues/13734#issuecomment-521743839.
Even after assigning 8gigs, my build still fails. Sourcemap is false as well. This didn’t happen when I was on ng5, after ng7, it broke altogether. I cannot even run webpack stats to see what is taking up so much data…
@filipesilva After upgrade to Angular v6, my builds are always out of memory when execute
ng build --prod
. But after i remove@types/lodash
, the build can be passed. So much thanks for @th0r . But the build time is still much slower than using Angular v5.(About double times). And I have already closed the build optimizer and using Node.js 10. My Angular version is6.0.6
. Cli version is6.0.8
. It seems the production build time is the main reason which blocking many users upgrade to new Angular version. About half year ago when i try to upgrade to Angular5, i met out of memory issue when i’m using the production build with AOT. I can’t find a solution so i can only wait. I wait for about 2 month and update to the latest Angular cli version, the AOT build works.BTW, currently if i build the production version in my local, it works. But when i try to build it in the CI(I’m using Appveyor), it will throw out of memory error until i remove
@types/lodash
as i mentioned above. But the CI build works well with Angular v5 and Cli version1.7.x
. For many scenarios of the deployment, the production build should be happened in the CI environment which means it may not have a very good hardware as your local PC. But it doesn’t mean that the build should not be passed in the CI.@filipesilva to summ up:
Node.js v10.1.0 with
--max_old_space_size=8192
/ webpack v4.8.3 / AoT build without minification:@types/lodash v4.14.109
-2.72gb / ~50 seconds
@types/lodash v4.14.70
-1.62gb / ~50 seconds
Without
max_old_space_size
set:@types/lodash v4.14.109
-out of memory error after ~20 minutes
@types/lodash v4.14.70
-1.33gb / ~52 seconds
P.S.
lodash v4.14.70
is not compatible with TS 2.7 out of the box - TS throws errornode_modules/@types/lodash/index.d.ts(13154,53): error TS2344: Type 'T' does not satisfy the constraint 'object'
. To fix it replace this line withisWeakSet<T extends object>(value?: any): value is WeakSet<T>;
.@gnagakarthik I use custom build configuration instead of
ng build
so the command in package.json looks like thisnode --max_old_space_size=8192 ./node_modules/.bin/gulp compile-scripts
and it works fine.Seems like you can set it via NODE_OPTIONS env variable.
@filipesilva @th0r I have a similar issue, I am using angular cli build with tfs build pipeline.
I use ng build --prod and the encounter the FATAL ERROR: CALL_AND_RETRY_LAST Allocation failed - JavaScript heap out of memory.
I know i have to increase the memory size, I am unsure how to do it. if i perform from cmd: node --max_old_space_size=4096 ./node_modules/.bin/ng build --prod, node is not valid command for ng
How do i correctly set the max_old_space_size as a global value and use ng build --prod or execute npm run <some npm command>?
using: Angular 7.2.0 “@angular-devkit/build-angular”: “~0.11.3” Node v8.11.3
Tried updating node to v 10.15.3 but the build times are same.
@filipesilva I’ve found an issue…but I don’t have words… That was because of updated lodash types… After reverting them back from
4.14.109
to4.14.70
memory usage went down to ~1.4gb and there is no “out of memory” error anymore.I can’t believe it! I didn’t even include it in the diff I posted above because I thought it doesn’t matter at all! WTF?!
My only assumption is that they added a few recursive types like PartialDeep that consume a lot of memory but I’m not sure about anything in this world anymore.
After few tests I downgrade to 6.0.0 and set sourceMap to false. And in fact upgrading to node 10 helped, but I still see a 2x to 3x times increase in build time between 6.0.0 and 6.0.1.