JavaScript heap out of memory

This article introduces the JavaScript heap out of memory error, including its causes, solutions, implementation details, and related resources. These steps can help improve efficiency when dealing with memory issues.

Jul 22, 2017 · 1 min read · 96 Words · -Views -Comments · Programming
Node.js Build Tools Angular 🇨🇳 阅读中文版
Read with AI

Choose an AI assistant

ChatGPT Open in a new tab with the article link and prompt
Claude Copy the prompt, then open Claude

Open Claude
Trouble reading the article?

If the prompt is missing, copy the full prompt below into your AI assistant. If the AI cannot read the article, paste the visible passage you want to discuss and add your question.

Problem

Recently during Angular development involving build packaging, JIT packaging worked fine, but when doing AOT packaging, it reported JavaScript heap out of memory and memory overflow, as shown below:

out of memory

After investigation, this issue can be resolved by setting higher memory space.

Solution

Increase max_old_space_size

For example, in my case where webpack packaging script commands are defined in package.json, it looks like this:

    "webpack": "node --max_old_space_size=4096 node_modules/webpack/bin/webpack.js"

After making this change, the packaging works fine.

Notes

  • Memory unit is MB
  • AOT compared to JIT has an additional ngc compilation step, so it does consume more memory.
Authors
Developer, digital product enthusiast, tinkerer, sharer, open source lover