- A heap overflow error was reported using NPM run dev to start the project today
-
CALL_AND_RETRY_LAST Allocation failed – JavaScript heap out of memory CALL_AND_RETRY_LAST Allocation failed – JavaScript heap out of memory We all know that Node is based on the V8 engine, and when using JavaScript in Node, you can only use partial memory (about 1.4GB on 64-bit systems and 0.7GB on 32-bit systems), so memory leaks can occur when projects are large.
The solution is to increase the node memory limit
- Add it to the scripts of package.json file
{
script:{
"ionic:build": "node --max-old-space-size=8192 ./node_modules/@ionic/app-scripts/bin/ionic-app-scripts.js build",
}
}
Copy the code
- If the first method doesn’t work, add node attributes to the node_modules/.bin/webpack-dev-server. CMD file. Add node after node –max-old-space-size=10240 MB
@IF EXIST "%~dp0\node.exe" ( "%~dp0\node.exe" "%~dp0\.. \webpack-dev-server\bin\webpack-dev-server.js" %* ) ELSE ( @SETLOCAL @SET PATHEXT=%PATHEXT:; .JS; =; % node --max-old-space-size=10240 "%~dp0\.. \webpack-dev-server\bin\webpack-dev-server.js" %* )Copy the code
- Vue-cli3 solution
"scripts": {
"serve": "vue-cli-service serve",
"build": "vue-cli-service build",
"fix-memory-limit": "cross-env LIMIT=4096 increase-memory-limit",
},
Copy the code
Install two dependency packages simultaneously
"DevDependencies" : {" happens - the memory - limit ":" ^ 1.0.3 ", "cross - env" : "^ 5.0.5"}Copy the code
This works by changing the permissions of all files in the.bin (usually the first folder) folder on node_modules