27

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.

lukaswelte
  • 2,951
  • 1
  • 23
  • 45
  • 39
    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. – Dan Abramov May 18 '17 at 15:14

6 Answers6

32

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

lukaswelte
  • 2,951
  • 1
  • 23
  • 45
28
"build": "react-scripts --max_old_space_size=4096 build"

This should work

Moslem Ben Dhaou
  • 6,897
  • 8
  • 62
  • 93
Андрей
  • 391
  • 3
  • 2
19

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

Arthur Levoyer
  • 191
  • 1
  • 3
11

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

Basavaraj Hadimani
  • 1,094
  • 12
  • 21
1

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

craco --max_old_space_size=4096 build
Joe Keene
  • 2,175
  • 21
  • 27
0

Add

ENV GENERATE_SOURCEMAP=false

in your docker file. This worked for me.

Thanks!