Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

create-react-app max_old_space_size not working

Facing an issue while build or run my project with create-react-app. It throws js heap out of memory error.

> yarn build
yarn run v1.6.0
$ react-scripts build
Creating an optimized production build...

<--- Last few GCs --->

[8792:0000021D06B28B70]  1492086 ms: Mark-sweep 1401.7 (1716.2) -> 1401.7 (1716.2) MB, 1474.4 / 0.0 ms  allocation failure GC in old space requested
[8792:0000021D06B28B70]  1493542 ms: Mark-sweep 1401.7 (1716.2) -> 1401.5 (1658.7) MB, 1455.7 / 0.0 ms  last resort GC in old space requested
[8792:0000021D06B28B70]  1494983 ms: Mark-sweep 1401.5 (1658.7) -> 1401.5 (1636.7) MB, 1439.7 / 0.0 ms  last resort GC in old space requested

<--- JS stacktrace --->

After searching on internet, i found a few suggestions and have added the following lines to my package start and build lines.

"start": "node --max_old_space_size=4096 node_modules/.bin/react-scripts start",
"build": "node --max_old_space_size=4096 node_modules/.bin/react-scripts build"

Now when i run "yarn start" or "yarn build" i get the following error.

> yarn build
yarn run v1.6.0
$ node --max_old_space_size=4096 node_modules/.bin/react-scripts build
D:\My-App\node_modules\.bin\react-scripts:2
basedir=$(dirname "$(echo "$0" | sed -e 's,\\,/,g')")
          ^^^^^^^

SyntaxError: missing ) after argument list
    at createScript (vm.js:80:10)
    at Object.runInThisContext (vm.js:139:10)
    at Module._compile (module.js:599:28)
    at Object.Module._extensions..js (module.js:646:10)
    at Module.load (module.js:554:32)
    at tryModuleLoad (module.js:497:12)
    at Function.Module._load (module.js:489:3)
    at Function.Module.runMain (module.js:676:10)
    at startup (bootstrap_node.js:187:16)
    at bootstrap_node.js:608:3
error Command failed with exit code 1.

Also I've removed my nodes_modules folder and reinstalled it again. But still the issue exists.

My development environment:

OS: Windows 10 Pro | Node version: v8.9.3 | npm version : v6.1.0 | yarn version: v1.6.0 | react-scripts version: 1.1.4

like image 686
bytecode Avatar asked May 29 '18 12:05

bytecode


1 Answers

Just copy paste from the comments. This question deserves an answer, even if that answer is already there in the comments section with small letters.

The solution: react-scripts --max_old_space_size=4096 start
This issue was addressed in github issues of create react app here.
Credits to @bytecode

like image 108
2 revs Avatar answered Nov 10 '22 01:11

2 revs