javascript - create-react-app max_old_space_size 不起作用

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

使用 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 专业版 |节点版本:v8.9.3 | npm 版本:v6.1.0 | yarn 版本:v1.6.0 | react 脚本版本:1.1.4

最佳答案

只需从评论中复制粘贴即可。这个问题值得一个答案,即使这个答案已经在评论部分用小写字母出现。
解决办法:react-scripts --max_old_space_size=4096 start此问题已在 create react app here 的 github 问题中得到解决.
致@ bytecode

关于javascript - create-react-app max_old_space_size 不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50584102/

相关文章:

service - 如何使用service.xml或Service Builder设置字符串列的大小?

c++ - 获取存储在 blob 中的 MySQL 图像大小

JavaScript 到 ActionScript

javascript - react redux 的 action 是如何访问 dispatch 和 getState 的?

javascript - AngularJS 提交函数不能多次调用服务函数

c++ - VC++中未初始化的内存块

c - 为什么内存会损坏?

javascript - 如何使 javascript 窗口位于所有其他窗口之上?

C++ 检查数组是否使用 'new' 创建

c++ - 为什么字符的大小只有 8 位?