Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.".

like image 635
Zag Avatar asked Jun 24 '19 18:06

Zag


People also ask

How do you set a variable to process an environment?

You can set the environment variable through process global variable as follows: process. env['NODE_ENV'] = 'production'; Works in all platforms.

How do I allocate more memory to node js?

Solution. The solution to run your Node. js app with increased memory is to start the process with an additional V8 flag: --max-old-space-size . You need to append your desired memory size in megabytes.


1 Answers

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

set NODE_OPTIONS=--max_old_space_size=4096

like image 115
Peter Boomsma Avatar answered Oct 02 '22 13:10

Peter Boomsma