Reputation:
Im getting this error when i run ng build --prod
92% chunk asset optimization <--- Last few GCs --->
[4136:0155D210] 443646 ms: Mark-sweep 703.5 (770.3) -> 703.6 (759.8) MB, 2162.2 / 0.0 ms (+ 0.0 ms in 0 steps since start of marking, biggest step 0.0 ms, walltime since start of marking 2163 ms) last resort GC in old space requested [4136:0155D210] 445794 ms: Mark-sweep 703.6 (759.8) -> 703.5 (759.8) MB, 2147.8 / 0.0 ms last resort GC in old space requested
<--- JS stacktrace --->
==== JS stack trace =========================================
Security context: 0369632D 1: create(this=036856A9 ) 2: _walk [034841A1 :~764] [pc=1CCAED1F](this=3A11A619 ,visitor=3BCEFD7D ) 3: /* anonymous */ [034841A1 :~969] [pc=1D3728E3](this=3A11BCBD ) 4: _walk [034841A1 :~968] [pc=1CCC1F3B](this=3A11BCBD
FATAL ERROR: CALL_AND_RETRY_LAST Allocation failed - JavaScript heap out of memory 1: node_module_register 2: v8::internal::Factory::NewStruct 3: v8::internal::Factory::NewPrototypeInfo
I tried everything. I reduced the usage of variables and checked for memory leaks and made very less callbacks in the ts file.
Im unable to figure out how to do it. I tried increasing the node memory by using 'npm i increase-memory-limit' and increased the limit to 2GB.
Im using angular 4. Node version is 8.9.4
Upvotes: 7
Views: 16339
Reputation: 380
I am getting this error while running
npm test run
For temporary, we can increase limit of --max_old_space_size
path: node_modules/@yarnpkg/index.js
then search for --max_old_space_size and then increase limit but it will be a temporary solution.
try this as it seems like permanent solution-- https://stackoverflow.com/a/57782016/1948482
Upvotes: 1
Reputation: 915
Try navigate to yourproject/node_modules and run following command:
node --max_old_space_size=5048 "%~dp0\..\@angular\cli\bin\ng" build --aot --prod
And if you want to make your life easier you can insert this in your package.json
file:
"scripts": {
"build-prod": "node --max_old_space_size=5048 ./node_modules/@angular/cli/bin/ng build --prod"
}
Then all you have to do now is running npm run build-prod
.
Upvotes: 8
Reputation: 363
You might want to look at how increase-memory-limit
increases the heap size under the hood.
The usual way is as follows:
node --max-old-space-size=8192 server.js
If it is somehow modifying the ng build
command you may want to try increasing the limit more.
Upvotes: 1
Reputation: 44
I had the same problem once building a JS application and it turns out there's a limit of the memory a node module can consume.
simply using this npm package has solved it for me : https://www.npmjs.com/package/increase-memory-limit
Upvotes: -1