Reputation:
How to solve the: FATAL ERROR: Ineffective mark-compacts near heap limit Allocation failed - JavaScript heap out of memory
1: 0xa08900 node::Abort() [/root/.nvm/versions/node/v12.18.1/bin/node] when running npm run build
on TypeScript project.
I have been trying the Fixes from my research here in Stackoverflow and other Forums but I am not winning. I updated from Node.js version 10 to version 12.18.1 but still, the problem persists. I tried to create a SWAP file but yet I didn't win. Previously the problem would go away by recreating a SWAP file. I am using Digital Ocean Ubuntu server 20.4. Please assist me to solve those issue
Upvotes: 4
Views: 40298
Reputation: 2951
Increase the node max memory size
// terminal
export NODE_OPTIONS=--max_old_space_size=8096
// Windows
set NODE_OPTIONS=--max_old_space_size=8096
Upvotes: 13
Reputation: 40681
Sounds like you need to allow a larger heap size (which by default is computed automatically based on available system memory -- swap files don't count for that).
The flag you need for that is --max-old-space-size
(with a value in megabytes), apparently one way of setting it is to run npm as follows:
node --max_old_space_size=4000 /usr/bin/npm run build
or you can use NODE_OPTIONS
or .npmrc
if you prefer.
If that doesn't help, or if you need more help, please provide some more information:
I updated from Node.js version 10 to version 12.18.1
Probably unrelated to your issue, but that's still a fairly old version. How about 12.20.0 (if it has to be the v12 line, which is in maintenance mode) or 14.15.1 (current "active LTS")?
/root/.nvm/...
Why do you run node as root??!! Don't ever run anything as root!
Upvotes: 2