FATAL ERROR: Ineffective mark-compacts near heap limit Allocation failed – JavaScript heap out of me

在这里插入图片描述

方法一

大多数时候,当您遇到此错误时,可能是因为内存泄漏、库的添加/版本升级或Node.js管理版本之间内存的方式存在差异(例如Node.js版本<= 10Node.js版本> 10)。

通常,仅增加分配给Node.js的内存就可以让您的程序运行,但可能并不能真正解决真正的问题,并且节点进程使用的内存仍然可能超过您分配的新内存。我建议在Node.js进程开始运行或更新到Node.js > 10时分析其内存使用情况。

也就是说,要增加内存,请在运行Node.js进程的终端中:

export NODE_OPTIONS="--max-old-space-size=8192"

或者对于 Windows:

Set NODE_OPTIONS="--max-old-space-size=8192"

其中 的值max-old-space-size可以是:[2048, 4096, 8192, 16384]

为了进一步清晰起见,更多示例:

export NODE_OPTIONS="--max-old-space-size=5120" # Increase to 5 GB
export NODE_OPTIONS="--max-old-space-size=6144" # Increase to 6 GB
export NODE_OPTIONS="--max-old-space-size=7168" # Increase to 7 GB
export NODE_OPTIONS="--max-old-space-size=8192" # Increase to 8 GB

# and so on...

# formula:
export NODE_OPTIONS="--max-old-space-size=(X * 1024)" # Increase to X GB

# Note: it doesn't have to be multiples of 1024.
# max-old-space-size can be any number of memory megabytes (MB) you have available.

查看max-old-space-size的当前值(以MB为单位)
要查看max-old-space-size(以MB为单位)的当前(不准确但非常接近)值,请在终端中运行

node -e 'console.log(v8.getHeapStatistics().heap_size_limit/(1024*1024))'

方法二

增加内存:在命令前加上:--max_old_space_size=8192,如下

  "scripts": {
    "dev": "webpack-dev-server --inline --progress --config build/webpack.dev.conf.js",
    "start": "npm run dev",
    "unit": "jest --config test/unit/jest.conf.js --coverage",
    "e2e": "node test/e2e/runner.js",
    "test": "npm run unit && npm run e2e",
    "lint": "eslint --ext .js,.vue src test/unit/specs test/e2e/specs",
    "build": "node --max_old_space_size=8192 build/build.js",
    "serve": "node --max_old_space_size=8192 node_modules/.bin/webpack-dev-server serve"
  },

如果你是vuepress可以在package.json中添加

 "scripts": {
   "docs:dev": "vuepress dev docs",
   "docs:build": "vuepress build docs",
   "docs:limit": "cross-env LIMIT=8192 increase-memory-limit"
 },

使用increase-memory-limit插件,增加node服务器内存限制

npm install -g increase-memory-limit
increase-memory-limit

或者

npm install cross-env increase-memory-limit

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
THE END
分享
二维码
< <上一篇
下一篇>>