29

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.

1
  • 42
    Since 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. Commented May 18, 2017 at 15:14

6 Answers 6

36

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

Sign up to request clarification or add additional context in comments.

7 Comments

This is giving an error : basedir=$(dirname.......) line 2 of react scripts. It says missing ) after argument list. PLease help
I have same issue, Our ubuntu server ram 1GB so what i need to do ?
For smal servers you need put less memory. To me works with --max_old_space_size=256
what is 4096 here 4096 GB?
This is 4096 MB so 4 GB
|
31
"build": "react-scripts --max_old_space_size=4096 build"

This should work

6 Comments

what is 4096 here 4096 GB or MB?
@vinayakshahdeo it means 4096 MB
I tried this and didn't work for me even after setting 8 Gb or 12 Gb
Getting FATAL ERROR: MarkCompactCollector: young object promotion failed Allocation failed - JavaScript heap out of memory
@Sandeepsandy I think I fixed all heap out of memory ocurrances by upgrading NodeJs.
|
21

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

Comments

12

One line answer, run on terminal -> export NODE_OPTIONS=--max_old_space_size=4096

Comments

1

If you're using craco build just add the flag in like the below

craco --max_old_space_size=4096 build

Comments

1

Add

ENV GENERATE_SOURCEMAP=false

in your docker file. This worked for me.

Thanks!

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.