create-react-app max_old_space_size无效

10

使用create-react-app构建或运行我的项目时遇到问题。它会抛出js heap out of memory错误。

> 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 --->
在搜索互联网后,我发现了一些建议并已添加了以下内容到我的软件包的启动和构建代码行中。
"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"
现在当我运行 "yarn start" 或者 "yarn build" 时,会出现以下错误。
> 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.

我已经删除了我的 nodes_modules 文件夹并重新安装了它。但问题仍然存在。

我的开发环境:

操作系统:Windows 10专业版 | Node 版本:v8.9.3 | npm 版本:v6.1.0 | yarn 版本:v1.6.0 | react-scripts 版本:1.1.4


2
由于这个问题长期未被回答,因此我来回答自己的问题。快速答案是 react-scripts --max_old_space_size=4096 start此问题已在 create react app 的 Github 问题中得到解决 这里 - bytecode
1个回答

9

只需从评论中复制粘贴。这个问题值得回答,即使那个答案已经在注释部分以小字体出现。

解决方法:react-scripts --max_old_space_size=4096 start
这个问题已经在create react app的github问题中得到了解决here.
感谢@bytecode


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接