Bijay Singh
Bijay Singh

Reputation: 849

Javascript out of memory during angular prod build

I am getting following error while doing a prod build for my angular 4 project in windows 10:

92% chunk asset optimization
<--- Last few GCs --->

[2608:000002518B1007B0]   578653 ms: Mark-sweep 1400.7 (1534.2) -> 1400.7 (1502.2) MB, 1409.9 / 0.0 ms  last resort
[2608:000002518B1007B0]   579952 ms: Mark-sweep 1400.7 (1502.2) -> 1400.7 (1501.2) MB, 1298.6 / 0.0 ms  last resort


<--- JS stacktrace --->

==== JS stack trace =========================================

Security context: 0000003DF7DA66A1 <JS Object>
    1: DoJoin(aka DoJoin) [native array.js:~97] [pc=0000032E01B053FC](this=000001F775C02311 <undefined>,q=0000010002582251 <JS Array[4]>,r=4,F=000001F775C023B1 <true>,B=000001F775C02471 <String[0]: >,A=000001F775C02421 <false>)
    2: Join(aka Join) [native array.js:~122] [pc=0000032E01E5AD22](this=000001F775C02311 <undefined>,q=0000010002582251 <JS Array[4]>,r=4,B=000001F775C02471 <String[0]...

FATAL ERROR: CALL_AND_RETRY_LAST Allocation failed - JavaScript heap out of memory

What I Tried: Edited webpack.cmd as below (as suggested in one of the SO posts), but this didn't helped:

@IF EXIST "%~dp0\node.exe" (
    "%~dp0\node.exe" --max_old_space_size=8048 
    "%~dp0\..\webpack\bin\webpack.js" %*
    ) ELSE (
    @SETLOCAL
    @SET PATHEXT=%PATHEXT:;.JS;=;%
    node --max_old_space_size=8048
    node  "%~dp0\..\webpack\bin\webpack.js" %*
)

Extra Info

@angular/cli: 1.0.0
node: 7.9.0
os: win32 x64
@angular/animations: 4.1.3
@angular/common: 4.1.3
@angular/compiler: 4.1.3
@angular/core: 4.1.3
@angular/forms: 4.1.3
@angular/http: 4.1.3
@angular/platform-browser: 4.1.3
@angular/platform-browser-dynamic: 4.1.3
@angular/router: 4.1.3
@angular/cli: 1.0.0
@angular/compiler-cli: 4.1.3

In all the github and SO pages for this issue, it is suggested to allocate more memory to node, I did that too, but didn't worked out. I badly need to do a prod build, please advice how can I overcome this issue

Upvotes: 1

Views: 1461

Answers (2)

Bijay Singh
Bijay Singh

Reputation: 849

I've changed max_old_space_size in ng.cmd file inside %AppData%\npm (Windows) and it did the trick.

I no longer face any issue while launching ng build --prod --env=prod --base-href .

Upvotes: 2

user7560588
user7560588

Reputation:

To actually increase the memory size you need to use the flag max_old_space_size with the file call. Change your code to:

@IF EXIST "%~dp0\node.exe" (
     "%~dp0\node.exe" --max_old_space_size=8048 
     "%~dp0\..\webpack\bin\webpack.js" %*
     ) ELSE (
     @SETLOCAL
    @SET PATHEXT=%PATHEXT:;.JS;=;%
  node --max_old_space_size=8048 "%~dp0\..\webpack\bin\webpack.js" %*
)

This should do the trick.

Upvotes: 0

Related Questions