node memory leak exhausted: FATAL ERROR: Ineffective mark-compacts near heap limit Allocation failed - JavaScript

The first thing I saw was a memory leak, and I identified the problem. Then I went crazy on Baidu, csdn search, and tried 3 methods, and the last one worked.

 

1):

Error when executing npm command: FATAL ERROR: Ineffective mark-compacts near heap limit Allocation failed - JavaScript heap out of me

Literal meaning: The JavaScript heap is out of memory. Because Node is based on the V8 engine, only part of the memory can be used when using memory through JavaScript in Node.
I tried deleting the .npmrc file under C:\Users{Account}\, but it didn't work.

Solution:
Install the plug-in through the increase-memory-limit plug-in: npm install -g increase-memory-limit
Execute the command: npx cross-env LIMIT=4096 increase-memory-limit
Finally execute: npm start to start the project
———— ————————————

2):

Node memory leak exhaustion solution:

When developing a project built using the latest Vue scaffolding vue-cli, due to frequent code modifications, memory overflow occurred and the following appeared:
FATAL ERROR: Ineffective mark-compacts near heap limit Allocation failed
(Fatal error: JavaScript heap when using any "NPM" command will run out of memory)

Three solutions:

One, you need to increase the amount of memory your node allows.

You can do this globally by
1. Open a cmd window
2. Run  setx NODE_OPTIONS --max_old_space_size=10240
3. Close all cmd/code editors
4. Re-open cmd and run node commands (npm, etc.) again
———————— ————————————————————————————————————————
Second, direct coverage
is simple and crude, directly replace scripts in package.json Contents of the serve command:

serve" : "node --max_old_space_size=4096 node_modules/.bin/vue-cli-service serve --open

Just run npm run serve or yarn serve during development.
————————————————————————————————————————————
3. Elegant coverage
and above The only difference between the methods is that there is no need to write the path of the vue-cli-service package. The code is more elegant and is not affected by the package address.

全局安装npx: npm i -g npx

Directly replace the serve instruction content under scripts in package.json:

serve": "npx --max_old_space_size=4096 vue-cli-service serve
开发时运行npm run serve或yarn serve

3):

Solution: add it in package .json and use   increase-memory-limit   to solve the problem

01) npm install increase-memory-limit #本项目中使用 [ 选择自己的方式 ]   # npm install -g increase-memory-limit 全局使用

02) npm install --save cross-env
03) 修改 package.json 如下:[ LIMIT大小自己设置 ]

"scripts": {
    "fix-memory-limit": "cross-env LIMIT=2048 increase-memory-limit"
  },

04) npm run fix-memory-limit(只需执行一次即可)

Guess you like

Origin blog.csdn.net/qq_42351675/article/details/131704901