Problem
Development projects for some time, as the project is getting bigger, the packaging time is correspondingly longer, and the memory of packaging increased. At this point, there is a problem, when publishing the project, there will be a JavaScript heap out of memory
wrong hint.
Such as:
The above error has been causing the project to be published.
Detailed Error content:CALL_AND_RETRY_LAST Allocation failed - JavaScript heap out of memory
Reason
Node
JavaScript
only partial memory (64-bit system: 1.4 gb,32 Bit system: 0.7 GB) can be used when using memory in, at this time, if the front-end project is very large, the Webpack
compile time will occupy a lot of system resources, if it is beyond the V8
engine Node
The default memory limit size creates a memory leak (JavaScript heap out of memory) error.
Solution Solutions
Since the V8
engine has a Node
default memory limit size, you can relax the memory size usage limit when the memory is low, and Node
you can Node
pass --max-old-space-size
or adjust the --max-new-space-size
memory size usage limit at startup.
But this approach needs to be set up everywhere, so a plugin needs to be installed increase-memory-limit
.
Use the following methods:
- Installation
npm install -g increase-memory-limit
- Run
increase-memory-limit
- NPM runs asynchronously
"scripts": { "fix-memory-limit": "cross-env LIMIT=2048 increase-memory-limit" }, "devDependencies": { "increase-memory-limit": "^1.0.3", "cross-env": "^5.0.5" }
Execute oncenpm run fix-memory-limit
Plugin: Increase-memory-limit
Webpack Package "JavaScript heap out of memory" error