JavaScript Full‑Stack: Heap Out of Memory
September 15, 2021•156 words
Lately my builds have been screaming “JavaScript heap out of memory.” It’s not just the Vue app I’m working on right now—I've hit the same wall with React and Angular projects, basically any front‑end bundle that swells beyond a modest size.
What finally steadied things down was a tiny change in my package.json
scripts:
package.json
{
"scripts": {
"serve": "NODE_OPTIONS=--max_old_space_size=4096 vue-cli-service serve",
"build": "NODE_OPTIONS=--max_old_space_size=4096 vue-cli-service build"
}
}
--max_old_space_size
tells V8 how much RAM it can allocate. Cranking it up to 4096 MB (or a higher value if your machine can spare it) gives the compiler enough breathing room to finish the job without blowing up.
Some tips:
- Cross-platform: You can use
cross-env
to set the environment variable.cross-env NODE_OPTIONS=--max_old_space_size=4096 vue-cli-service serve
"scripts": {
"dev": "cross-env NODE_OPTIONS=--max_old_space_size=4096 vue-cli-service serve",
"build": "cross-env NODE_OPTIONS=--max_old_space_size=4096 vue-cli-service build"
},
"devDependencies": {
"cross-env": "10.x",
}
- Adjust as needed: if you have more RAM, increase the number.