Webpack Package "JavaScript heap out of memory" error

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.