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 ?
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 ?
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"
}
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.
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
./node_modules/.bin/ng
instead of ./node_modules/@angular/cli/bin/ng
. So if the path changes anytime, you use the symlink. –
Quintain export NODE_OPTIONS=--max_old_space_size=4096
While upping the heap size can for sure resolve this issue, I also recommend checking your supported browsers, see 'https://github.com/browserslist/browserslist'
When my app stopped building with 12gb I looked into other solutions and for me I was able to limit to browsers we actually support and I reduced heap size to 8gb (I suspect I could go lower but didn't bother testing)
My config now
# Browsers that we support
# Take caution when expanding out this list, as builds will require more ram '--max_old_space_size'
last 2 Chrome versions,
last 2 FireFox versions,
last 2 Edge versions,
last 2 Safari versions
last 2 Opera versions
© 2022 - 2024 — McMap. All rights reserved.
node --max_old_space_size=4096
– Yugoslav