0
votes

Suddenly builds started failing with following error :

2019-01-03T12:57:22.2223175Z EXEC : FATAL error : CALL_AND_RETRY_LAST Allocation failed - JavaScript heap out of memory
error MSB3073: The command "node node_modules/webpack/bin/webpack.js --env.prod" exited with code 3.

I have tried all the solutions available like :
1) Updating the virtual memory of Windows
2) Updating the NPM version and Node version
3) Also tried adding command to increase --max_old_space_size

Still facing the same issue while Publishing the angular APP. It works on local but failing on build server while publishing On local getting following error :

    <--- Last few GCs --->

[2212:000002BC74FB20D0]   152613 ms: Mark-sweep 1411.4 (1466.9) -> 1411.4 (1466.9) MB, 2117.6 / 0.0 ms  last resort GC in old space requested


<--- JS stacktrace --->

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

Security context: 0000032354625EE1 <JSObject>
    1: bindContainer [node_modules\typescript\lib\typescript.js:~22960] [pc=000003AD4C9DBFB9](this=000000063100BE21 <JSGlobal Object>,node=000001B7FE6A7E61 <NodeObject map = 0000020A3EA721A1>,containerFlags=45)
    2: visitNodeArray [node_modules\typescript\lib\typescript.js:~15947] [pc=000003AD4C9A32A5](this=000000063100BE21 <JSGloba...
1
You say you've tried using the --max-old-space-size option (note: no underscores). How did you run that command, was it something like this? node --max-old-space-size=8192 node_modules/webpack/bin/webpack.js --env.prodRobC
@RobC yes i have added that in Package.json under script section but still got the same issue.Sagar K

1 Answers

1
votes

This error occurs when the memory allocated for the execution application is less than the required memory when run application, by default Node allocates a certain size of memory.

You can increase this size for every build changing your package.json, so even local or in the server the application will prepare the publish with ideal size of memory allocation.

"build": "node --max-old-space-size=4096 ./node_modules/@angular/cli/bin/ng build --prod",

Another option is inside your npm folder, edit the ng.cmd to always increase the memory size.

@IF EXIST "%~dp0\node.exe" (
  "%~dp0\node.exe" --max_old_space_size=8192 "%~dp0\..\@angular\cli\bin\ng" %*
) ELSE (
 @SETLOCAL
 @SET PATHEXT=%PATHEXT:;.JS;=;%
 node --max_old_space_size=8192 "%~dp0\..\@angular\cli\bin\ng" %*
)

And a less elegant solution is using a dependency that handle this problem. Run from the root location of your project:

npm install -g increase-memory-limit
increase-memory-limit

In the server you will need to make a script for these steps before the publish. More details about the package here: https://www.npmjs.com/package/increase-memory-limit