iLoungeiLounge
  • News
    • Apple
      • AirPods Pro
      • AirPlay
      • Apps
        • Apple Music
      • iCloud
      • iTunes
      • HealthKit
      • HomeKit
      • HomePod
      • iOS 13
      • Apple Pay
      • Apple TV
      • Siri
    • Rumors
    • Humor
    • Technology
      • CES
    • Daily Deals
    • Articles
    • Web Stories
  • iPhone
    • iPhone Accessories
  • iPad
  • iPod
    • iPod Accessories
  • Apple Watch
    • Apple Watch Accessories
  • Mac
    • MacBook Air
    • MacBook Pro
  • Reviews
    • App Reviews
  • How-to
    • Ask iLounge
Font ResizerAa
iLoungeiLounge
Font ResizerAa
Search
  • News
    • Apple
    • Rumors
    • Humor
    • Technology
    • Daily Deals
    • Articles
    • Web Stories
  • iPhone
    • iPhone Accessories
  • iPad
  • iPod
    • iPod Accessories
  • Apple Watch
    • Apple Watch Accessories
  • Mac
    • MacBook Air
    • MacBook Pro
  • Reviews
    • App Reviews
  • How-to
    • Ask iLounge
Follow US

Articles

Articles

How To Fix The “JavaScript heap out of memory” Error

Last updated: Jul 11, 2022 6:37 am UTC
By Lucy Bennett
How To Fix The "JavaScript heap out of memory" Error

Those who write complicated Node.js applications can run into the “JavaScript heap out of memory” error quite often. It can also happen when you run a program downloaded from another project. Check this guide to understand this error and the solution for it.


How To Fix The “JavaScript heap out of memory” Error

How Node.js Manages Memory

Node.js sets some memory limits by default to prevent applications from using too much memory and bogging down the whole system. The actual limits depend on your system’s architecture and the version of Node.js.

How To Fix The "JavaScript heap out of memory" Error

4GB of heap memory is the limit of the latest 64-bit Node.js versions. It consists of two spaces: old and new space. The old space is where Node.js stores older objects. Its size is controlled by the –max-old-space-size flag.


When your application produces a lot of objects, they can fill up the old heap space quickly, and Node.js will crash with a “JavaScript heap out of memory” error message.

How To Fix The Problem

You can avoid the error by raising the memory limit set by Node.js with the –max-old-space-size flag. Its value (in MB) is the new memory limit.

node –max-old-space-size=8192 yourscript.js

This command allows Node.js to execute yourscript.js with up to 8GB (8192MB) memory allocated. If you want to set this flag permanently, add it as an environment variable in your system.


On Linux/macOS, run this command:

export NODE_OPTIONS=–max-old-space-size=8192

On Windows: go to the Control Panel and select System. In the Advanced System Settings ta, click Environment Variables and then select New.

Enter NODE_OPTIONS and –max-old-space-size=8192 in the Variable name and Variable value fields, respectively. Finally, click Enter.

Conclusion

The “JavaScript heap out of memory” error happens when a Node.js program consumes too much memory in the old heap space. Raise the limit with the –max-old-space-size flag, and you should avoid the issue. Visit ITtutoria to learn more about similar errors


Latest News
11-inch M4 iPad Air $40 Off
11-inch M4 iPad Air $40 Off
1 Min Read
Apple To Announce Plans For 50th Anniversary
Apple To Announce Plans For 50th Anniversary
1 Min Read
Teardown Video for MacBook Neo Released
Teardown Video for MacBook Neo Released
1 Min Read
Updates and New Games Coming to Apple Arcade
Updates and New Games Coming to Apple Arcade
1 Min Read
The AirPods 4 with ANC is $60 off
The AirPods 4 with ANC is $60 off
1 Min Read
MacBook Pro Anticipated to Be Feature-Packed
MacBook Pro Anticipated to Be Feature-Packed
1 Min Read
Samsung and Apple Tie For Number One In Smartphone Production
Samsung and Apple Tie For Number One In Smartphone Production
1 Min Read
Flight Sim ‘X-Plane 12’ Coming To Vision Pro
Flight Sim ‘X-Plane 12’ Coming To Vision Pro
1 Min Read
13-inch M4 iPad Air Is $50 Off
13-inch M4 iPad Air Is $50 Off
1 Min Read
New HomePod and Apple TV Tied With Revamped Siri Release
New HomePod and Apple TV Tied With Revamped Siri Release
1 Min Read
iPhone Manufacturing in India Boosted
iPhone Manufacturing in India Boosted
1 Min Read
F1 Promotional Video Stars Tim Cook
F1 Promotional Video Stars Tim Cook
1 Min Read

iLounge logo

iLounge is an independent resource for all things iPod, iPhone, iPad, and beyond. iPod, iPhone, iPad, iTunes, Apple TV, and the Apple logo are trademarks of Apple Inc.

This website is not affiliated with Apple Inc.
iLounge © 2001 - 2025. All Rights Reserved.
  • Contact Us
  • Submit News
  • About Us
  • Forums
  • Privacy Policy
  • Terms Of Use
Welcome Back!

Sign in to your account

Lost your password?