【问题标题】:create-react-app max_old_space_size not workingcreate-react-app max_old_space_size 不起作用
【发布时间】:2018-11-08 02:15:28
【问题描述】:

在使用 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 --->

在网上搜索后,我找到了一些建议,并将以下几行添加到我的 package start 和 build 行中。

"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 专业版 |节点版本:v8.9.3 | npm 版本:v6.1.0 |纱线版本:v1.6.0 |反应脚本版本:1.1.4

【问题讨论】:

  • 由于很长一段时间都没有回答,因此回答了我自己的问题。快速回答是 react-scripts --max_old_space_size=4096 start 这个问题已在创建反应应用程序的 github 问题中得到解决 [这里][1]。 [1]:github.com/facebook/create-react-app/issues/4536

标签: javascript memory size create-react-app heap-memory


【解决方案1】:

只需从 cmets 复制粘贴即可。这个问题值得一个答案,即使那个答案已经在带有小写字母的 cmets 部分中。

解决方案:react-scripts --max_old_space_size=4096 start
此问题已在 create react app here 的 github 问题中得到解决。
感谢@bytecode

【讨论】:

    猜你喜欢
    • 2021-03-05
    • 1970-01-01
    • 2022-01-23
    • 2018-09-16
    • 2018-12-21
    • 2021-06-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多