5

Angular2 cli Project Production Build [ng build -prod] getting struck on 92% and getting error message like, running out of heap memory. Is there any solution for it? Project consists of huge number of components. Normal build is working fine [ng build]

Screenshot

Thank you

Roshin Thomas
  • 123
  • 1
  • 2
  • 12

3 Answers3

3

There is only one workaround today.

Open ./node_modules/.bin/ng.cmd and add --max_old_space_size option

@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" %*
)

Or you can upgrade your computer:)

Related issue on github

yurzui
  • 205,937
  • 32
  • 433
  • 399
  • 1
    Thanks yurzui, but node_modules folder is dynamically creating file na? when we run npm install, setting "max_old_space_size" may work in our system, but many people work together, this cant be solve using setting memory size on each machine? is there any quick solution to add it in package.json file? so it will run and execute on all machines. – Roshin Thomas Aug 03 '17 at 06:12
  • running on 8 GB RAM :) – Roshin Thomas Aug 03 '17 at 06:14
0

If you are working with a Node Version >= 8, you can use the solution posted in Node.js heap out of memory:

In your package.json file, replace ng build xxx with node --max_old_space_size=8192 ./node_modules/@angular/cli/bin/ng build xxx

The value 8192 is the space in MB which node and angular as well will be allowed to use

hoffmanuel
  • 403
  • 1
  • 5
  • 14
-1

Please check the version of Angular CLI, If its 1.2.6 downgrade it to 1.2.1. It will work. I too have the same issue and solved by this mean. NB: it's only a temporary fix. Hope cli team will solve the issue ASAP.

Aswin KV
  • 1,710
  • 2
  • 12
  • 23
  • Getting error like : ERROR in ./src/main.ts Module not found: Error: Can't resolve './$$_gendir/app/app.module.ngfactory' in 'D:\projectpath\src' @ ./src/main.ts 3:0-74 @ multi ./src/main.ts – Roshin Thomas Aug 04 '17 at 05:14