JavaScript heap out of memory in angular 2

拈花ヽ惹草 提交于 2019-12-05 20:09:04

try to modify the files and replace their contents with the following: (in the folder : node_modules\bin)

Modify ng.cmd:

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

Modify ngc.cmd :

@IF EXIST "%~dp0\node.exe" (
  "%~dp0\node.exe" --max_old_space_size=5048 "%~dp0\..\@angular\compiler-cli\src\main.js" %*
) ELSE (
  @SETLOCAL
  @SET PATHEXT=%PATHEXT:;.JS;=;%
  node --max_old_space_size=5048 "%~dp0\..\@angular\compiler-cli\src\main.js" %*
)
Bharat Banavalikar

for angular 7, I increased the maximum memory allocated for budgets in angular.json file.

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

then ran the following command: node --max_old_space_size=10500 'node_modules/@angular/cli/bin/ng' build --prod

in your case you should try to run this: node --max_old_space_size=10500 'node_modules/@angular/cli/bin/ng' serve --aot

This issue comes if the angular app will become bigger in size to compile. Please increase your node ram memory that will solve the issue. (Default node ram memory is 1600mb, increase it to around 3200)

I had the same issue In my tsconfig.json i had

"include": [ "**/*" ],

after removing this include, the ng build behave normal again

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!