当前位置:   article > 正文

ReactJS Start/build内存溢出_react-scripts build 内存

react-scripts build 内存

1.执行start命令或者build命令内存溢出问题

.FATAL ERROR: CALL_AND_RETRY_LAST Allocation failed - JavaScript heap out of memory

1.1使用的scripts脚本命令如下:
"scripts": {
"clean": "rimraf dist",
"start": "better-npm-run start",
"deploy:prod": "better-npm-run deploy:prod",
"codecov": "cat coverage/*/lcov.info | codecov",
"snippet": "node snippet"
},
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7

.无论使用start本地命令还是执行deploy:prod 打包命令,均报*FATAL ERROR: CALL_AND_RETRY_LAST Allocation failed - JavaScript heap out of memory
*错误,详细如下所示:

<--- Last few GCs --->

   58003 ms: Mark-sweep 1350.6 (1434.6) -> 1350.5 (1434.6) MB, 753.0 / 0.0 ms [allocation failure] [GC in old space requested].
   58751 ms: Mark-sweep 1350.5 (1434.6) -> 1350.5 (1434.6) MB, 747.6 / 0.0 ms [allocation failure] [GC in old space requested].
   59479 ms: Mark-sweep 1350.5 (1434.6) -> 1352.9 (1404.6) MB, 728.1 / 0.0 ms [last resort gc].
   60211 ms: Mark-sweep 1352.9 (1404.6) -> 1355.4 (1404.6) MB, 731.9 / 0.0 ms [last resort gc].

<--- JS stacktrace --->

==== JS stack trace =========================================

Security context: 0000017B93ACFB61 <JS Object>
    1: init_scope_vars [0000017B93A04381 <undefined>:~3382] [pc=0000021C499F308D] (this=000003B07C026939 <an AST_Function with map 000001FA502ACAB9>,nesting=3)
    2: visit [0000017B93A04381 <undefined>:~3246] [pc=0000021C499EFC85] (this=000003CB4FA172A1 <a TreeWalker with map 000001FA502AEB61>,node=000003B07C026939 <an AST_Function with map 000001FA502ACAB9>,descend=000003EF887DA4C9 <JS Func...

FATAL ERROR: CALL_AND_RETRY_LAST Allocation failed - JavaScript heap out of memory
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16

错误信息就如上面展示的这样,查看了活动指示器node分配的内存最大到1.5g的时候就无法增长,本人32g的电脑运存.其实就是在执行打包/启动命令的时候,所需要的内存大于1.5g,而默认分配的最多1.5g,就会导致这个问题

1.2在使用打包/启动命令的时候,增加内存参数,
  • 1.2.1 增加内存方式1:

      	"betterScripts": {
          	"dev": {
            "command": "nodemon --exec babel-node bin/server",
            "env": {
              "NODE_ENV": "development",
              "DEBUG": "app:*"
            }
          },
          "deploy": {
            "command": "npm run clean && npm run compile",
            "env": {
              "DEBUG": "app:*"
            }
          },
          "deploy:dev": {
            "command": "npm run deploy",
            "env": {
              "NODE_ENV": "development",
              "DEBUG": "app:*"
            }
          },
          "deploy:prod": {
            "command": "NODE_OPTIONS='--max-old-space-size=4096' npm run deploy",
            "env": {
              "NODE_ENV": "production",
              "DEBUG": "app:*"
            }
          },
          "start": {
            "command": "NODE_OPTIONS='--max-old-space-size=4096' babel-node  bin/server",
            "env": {
              "DEBUG": "app:*"
            }
          },
          "test": {
            "command": "babel-node ./node_modules/karma/bin/karma start build/karma.conf",
            "env": {
              "NODE_ENV": "test",
              "DEBUG": "app:*"
            }
          }
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40
    • 41
  • 1.2.2.增加内存方式2:

      "betterScripts": {
          	"dev": {
            "command": "nodemon --exec babel-node bin/server",
            "env": {
              "NODE_ENV": "development",
              "DEBUG": "app:*"
            }
          },
          "deploy": {
            "command": "npm run clean && npm run compile",
            "env": {
              "DEBUG": "app:*"
            }
          },
          "deploy:dev": {
            "command": "npm run deploy",
            "env": {
              "NODE_ENV": "development",
              "DEBUG": "app:*"
            }
          },
          "deploy:prod": {
            "command": "npm run deploy",
            "env": {
              "NODE_ENV": "production",
              "DEBUG": "app:*",
              "NODE_OPTIONS": "--max_old_space_size=10240"
            }
          },
          "start": {
            "command": "babel-node  bin/server",
            "env": {
              "DEBUG": "app:*",
              "NODE_OPTIONS": "--max_old_space_size=10240"
            }
          },
          "test": {
            "command": "babel-node ./node_modules/karma/bin/karma start build/karma.conf",
            "env": {
              "NODE_ENV": "test",
              "DEBUG": "app:*"
            }
          }
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40
    • 41
    • 42
    • 43

1.webpack 版本:1.12.14

2.node 版本:V8.16.0

3.npm 版本:6.4.1

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/繁依Fanyi0/article/detail/651702
推荐阅读
相关标签
  

闽ICP备14008679号