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 "npm start" or "npm build" i get the following error.
`
npm start
[email protected] start D:\my-apps
node --max_old_space_size=4096 node_modules/.bin/react-scripts start
D:\my-appsnode_modules.binreact-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
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! [email protected] start:node --max_old_space_size=4096 node_modules/.bin/react-scripts start
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the [email protected] start script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm ERR! A complete log of this run can be found in:`
Yes, the issue exists after deleting node_modules folder and reinstalling through npm
Environment:
OS: Windows 10 Pro
Node: 8.9.3
Yarn: 1.6.0
npm: 6.1.0
Watchman: Not Found
Xcode: N/A
Android Studio: Not Found
Packages: (wanted => installed)
react: ^16.2.0 => 16.4.0
react-dom: ^16.2.0 => 16.4.0
react-scripts: 1.1.4 => 1.1.4
Does this help? https://github.com/nodejs/node/issues/8117#issuecomment-239954661
ie perhaps call node_modules/react-scripts/scripts/start.js directly?
This should work:
react-scripts --max_old_space_size=4096 start
@Timer Big thanks. This has really worked. Is this documented anywhere?
No, PRs welcome! :)
@Timer this is working, build successfully, but the output files are not correct.
@Timer @andyliu-417 @bugzpodder is this a viable solution? Or is your bundle acctually getting wrong @andyliu-417 ?
Most helpful comment
This should work: