Increase JavaScript Heap size in create-react-app project
Solution 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
"build": "react-scripts --max_old_space_size=4096 build"
This should work
Solution 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
One line answer, run on terminal -> export NODE_OPTIONS=--max_old_space_size=4096
Solution 5
If you're using craco build
just add the flag in like the below
craco --max_old_space_size=4096 build
Comments
-
lukaswelte almost 2 years
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.
-
Dan Abramov almost 7 yearsSince those scripts are just JS files in a special directory you should be able to call the Node process like you usually do, and pass
node_modules/.bin/react-scripts
as the argument to it. It is symlinked to the actual script.
-
-
Dhiraj Gandhi over 5 yearsThis is giving an error : basedir=$(dirname.......) line 2 of react scripts. It says missing ) after argument list. PLease help
-
Mitul Marsoniya about 5 yearsI have same issue, Our ubuntu server ram 1GB so what i need to do ?
-
dsandrade about 4 yearsFor smal servers you need put less memory. To me works with --max_old_space_size=256
-
vinayak shahdeo almost 4 yearswhat is 4096 here 4096 GB?
-
vinayak shahdeo almost 4 yearswhat is 4096 here 4096 GB or MB?
-
lukaswelte almost 4 yearsThis is 4096 MB so 4 GB
-
PaulMest over 3 years@vinayakshahdeo it means 4096 MB
-
Pavan Jadda about 3 yearsI tried this and didn't work for me even after setting 8 Gb or 12 Gb
-
S.. about 2 yearsthis doesn't work for me, it still uses over 1gb of ram (when I set it to 256) and the processor goes to 300+%. Am I missing something? Is there any other way to constrain resource usage?
-
fabpico about 2 yearsGetting
FATAL ERROR: MarkCompactCollector: young object promotion failed Allocation failed - JavaScript heap out of memory
-
fabpico about 2 yearsGetting
FATAL ERROR: CALL_AND_RETRY_LAST Allocation failed - JavaScript heap out of memory