I am getting an heap out of memory error while ng build --prod ,Is there any work around. its building fine when --aot=false.
Any idea ?
My team was facing the same issue and this is how we resolved.
While building the project instead of ng build --prod
use this
node --max_old_space_size=8192 ./node_modules/@angular/cli/bin/ng build --prod --build-optimizer
OR
Just add above string in your package.json file like this and to build use just npm run prod
,
{
"name": "Deva_Application",
"version": "1.0.0",
"scripts": {
"ng": "ng",
"start": "ng serve --proxy-config proxy.conf.json",
"prod": "node --max_old_space_size=64384 ./node_modules/@angular/cli/bin/ng build --prod --build-optimizer --output-hashing=none",
"build": "ng build",
"test": "ng test",
"lint": "ng lint",
"e2e": "ng e2e"
},
...
}
In case of large project increase the --max_old_space_size to 16384 to 64384.
Try running build script in package json by the following script:
"scripts": {
"build-prod": "node --max_old_space_size=5048 ./node_modules/@angular/cli/bin/ng build --prod"
}
Reference
export NODE_OPTIONS=--max_old_space_size=4096
Here are the steps i have done to fix the issue based on above post and its worked well for me.
Step-1
Open package.json
Add this code under scripts
"build-prod": "node --max_old_space_size=5048 ./node_modules/@angular/cli/bin/ng build --prod"
Step-2
Open terminal and run execute this code "npm run build-prod"
Hope this helps