How to use the NODE_OPTIONS environment variable to set the max_old_space_size globally in Windows?

74,654

export is a Linux command. You can use set for Windows:

set NODE_OPTIONS=--max_old_space_size=4096

Share:
74,654
Zag
Author by

Zag

Updated on July 14, 2022

Comments

  • Zag
    Zag almost 2 years

    Workaround to fix heap out of memory when running node binaries (which is a common issue when using TypeScript 2.1+ and webpack) is increasing the max mem for node.

    increase-memory-limit is a package to do that. In the link, it says

    As of Node.js v8.0 shipped August 2017, you can now use the NODE_OPTIONS environment variable to set the max_old_space_size globally. export NODE_OPTIONS=--max_old_space_size=4096

    But how do I set that environment variable in Windows? In powershell, it is giving me the error "export : The term 'export' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.".

  • godblessstrawberry
    godblessstrawberry over 4 years
    how to check this was applied?
  • Andrey
    Andrey over 4 years
    this will help you v8.getHeapStatistics().total_available_size / 1024 / 1024 as of version 10.14.1 both command line arg and environment variable NODE_OPTIONS work
  • Davi Daniel Siepmann
    Davi Daniel Siepmann about 4 years
    isn't set suppose to persist between sections? I mean, I close my terminal, the problem is already there.... If not, is there a way to get it persisted ?
  • M Miller
    M Miller about 4 years
    I think you can use setx to persist environment variables on Windows Server. It varies on other versions.
  • Dilip Kumar Yadav
    Dilip Kumar Yadav over 2 years
    After setting it with set NODE_OPTIONS=--max_old_space_size=4096 When I am checking it with: node -e 'console.log(v8.getHeapStatistics().heap_size_limit/(1024*10‌​24))' It have not been increased.....