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

ng build fail with 'JavaScript heap out of memory' with patch 6.0.3

Open ArnaudBarre opened this issue 8 years ago • 55 comments

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.

ArnaudBarre avatar May 17 '18 09:05 ArnaudBarre

@th0r it is expected that at some point you need to increase the memory limit. That is not a bug. Larger projects will need more resources to build. Since NodeJS projects have a default memory limit, it will be reached at some point.

One can argue that the current memory usage is too high. I wouldn't say that 2 minutes to build a project for production is too long though. I wouldn't even say 2mins to build a large project for development is too long, as long as rebuilds are short.

I don't know the specifics of your project, but please bear in mind that it's not all just your source code. You might not have a huge amount of source TS files but still have a lot of code in imported libraries.

filipesilva avatar Jan 30 '19 12:01 filipesilva

I wouldn't say that 2 minutes to build a project for production is too long though.

But it's not for production - both sourcemaps and minification are turned off. If I turn them on stats become 4.6 mins / ~5gb mem at peak.

I think 5gb of ram is a little bit too much.

th0r avatar Jan 30 '19 12:01 th0r

I noticed this as well after @types/lodash was added to our project. Cranked up the mem limit and haven't looked back. I'm interested to know if there's a better way or if turning up the mem is hte suggested solution.

djohns2021 avatar Jan 31 '19 20:01 djohns2021

bump

kflo avatar Feb 15 '19 14:02 kflo

@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 ?

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.

gnagakarthik avatar Mar 13 '19 03:03 gnagakarthik

@gnagakarthik I use custom build configuration instead of ng build so the command in package.json looks like this node --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.

th0r avatar Mar 13 '19 07:03 th0r

I run since a few day's also in this issue and done my workaround as follow:

image

node --max_old_space_size=8192 node_modules/@angular/cli/bin/ng serve --prod
node --max_old_space_size=8192 node_modules/@angular/cli/bin/ng build --prod

node --max_old_space_size=8192 node_modules/@angular/cli/bin/ng serve -c myenv
node --max_old_space_size=8192 node_modules/@angular/cli/bin/ng build -c myenv

It works actually fine for my usage with the default ng server/build process. I hope not to run in it soon again...

JohnnyDevNull avatar Mar 14 '19 09:03 JohnnyDevNull

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 like

"scripts": {
    "ng": "ng",
    "start": "ng serve",
    "build": "ng build",
    "build:prod": "node --max_old_space_size=8192 node_modules/@angular/cli/bin/ng build --prod",
    "test": "ng test",
    "lint": "ng lint",
    "e2e": "ng e2e"
  }

and now run npm run build:prod

kalimulhaq avatar Apr 09 '19 05:04 kalimulhaq

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..

aijazkhan81 avatar Apr 13 '19 13:04 aijazkhan81

Increase maximum memory allocated for budgets in angular.json

"budgets": [ { "type": "initial", "maximumWarning": "2mb", "maximumError": "11mb" } ]

and used this command node --max_old_space_size=10500 'node_modules/@angular/cli/bin/ng' build --prod

bharat-banavalikar avatar Apr 24 '19 05:04 bharat-banavalikar

We are seeing this on dev builds as well. We used ionic to create or project and it uses architect. I am wondering if this has something to do with architect not managing memory correctly. Maybe file copies as we have a lot of assets that architect is copying.

Also, we were not seeing this issue under ng 5 before the migration to ng7

j3gb3rt avatar Apr 28 '19 20:04 j3gb3rt

Upgraded to Angular 8.1 from 7.2.15. Immediately saw the issue, out-of-memory. Same configuration, but 8 builds for both ES2015 and ES5, I suppose this is the issue.

Solved by increasing the Node memory limit from the default 1.5GB to 2.0GB. This might mean incurring in higher cost if you're on, e.g., AWS.

lppedd avatar Jul 03 '19 14:07 lppedd

I'm getting this message with cli 8.2.1: allocation failure scavenge might not succeed...Very long string[7203]...typescript.js...FATAL ERROR: Ineffective mark-compacts near heap limit Allocation failed - JavaScript heap out of memory.

adding --max_old_space_size=8000 didn't help

"@angular-devkit/build-webpack": "^0.802.1", "@angular-devkit/build-angular": "^0.802.1", "@angular-devkit/build-ng-packagr": "^0.802.1",

thoughts?

zehavibarak avatar Aug 15 '19 02:08 zehavibarak

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.

filipesilva avatar Aug 15 '19 18:08 filipesilva

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.