'Increase JavaScript Heap size in create-react-app project
Node features the way to increase the heap size via passing in the --max-old-space-size command line flag.
In create-react-app projects everything depends on the use of react-scripts.
How can I pass in this parameter in such projects and where should I best do that?
Thank you for help.
Solution 1:[1]
Thanks a lot to @dan-abramov as his comment is the answer! (Give him the vote up in case you come across this).
You can just put e.g. node --max_old_space_size=4096 node_modules/.bin/react-scripts start in there instead of react-scripts start
Solution 2:[2]
"build": "react-scripts --max_old_space_size=4096 build"
This should work
Solution 3:[3]
You can disable generation of source maps as described in https://create-react-app.dev/docs/advanced-configuration
Indeed as per the documentation:
When set to false, source maps are not generated for a production build. This solves out of memory (OOM) issues on some smaller machines.
Which is the case when you got an Heap Out Of Memory error
To do so, create a .env file and add GENERATE_SOURCEMAP=false
Solution 4:[4]
One line answer, run on terminal -> export NODE_OPTIONS=--max_old_space_size=4096
Solution 5:[5]
If you're using craco build just add the flag in like the below
craco --max_old_space_size=4096 build
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | lukaswelte |
| Solution 2 | Moslem Ben Dhaou |
| Solution 3 | |
| Solution 4 | Basavaraj Hadimani |
| Solution 5 | Joe Keene |
