Node - 'JavaScript heap out of memory'

Running my AOT build of my angular application failed with this error:

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

Using an NPM package to fix

Someone implemented an NPM package for this.

  1. install https://www.npmjs.com/package/increase-memory-limit globally
  2. run increase-memory-limit in the root of your project

Manual fix

  1. Navigate to %appdata% -> npm folder
  2. Open ng.cmd in your favorite editor
  3. Add --max_old_space_size=8192 to the IF and ELSE block

My node.cmd file looks like this after the change:

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