Reputation: 29464
I need to run npm install
with 8GB memory limit on NodeJS 14 on Windows 10 (with 16GB RAM).
I have tried the following to no avail:
node --max-old-space-size=8192 "C:\Program Files\nodejs\npm" install
- unexpected behavior but still seems to be at 4GB after using CTRL + C
set NODE_OPTIONS=--max-old-space-size=8192&&npm install
- still 4GB
Adding NODE_OPTIONS environment variable (to both User and System variables) - still 4GB
Related questions:
Upvotes: 3
Views: 27779
Reputation: 11819
You haven't shown any troubleshooting results, thus far, that leads me to believe that the issue is being caused by the "HEAP's MAX_SIZE
Env Variable", nor have you shown any evidence that the variable isn't being assigned the value that you are attempting to assign to it. I am not saying that the issue isn't being caused by the env Variable. However, I am saying, that more troubleshooting needs to be done to know for certain, what the underlying cause to your issue is..
Personally, from what you have shown the community thus far, I believe that the problem is due to running out of memory in a location other than the heap, which if your using a typical PC with Windows 10, its probably your machine that doesn't have enough memory, not period, but at the moment you attempt to do the download.
In my machine I have:
My Operating Systems
I use Linux, but I got Windows for Free because it was cheaper for me to buy a new PC, and upgrade it, than buy the parts seperatly. I never boot to windows, so its always sitting as an untouched fresh install.
Currently I just upgraded to Fedora Workstation 36.
TESTING
I ran performance test using a node program that implements child processes on other threads, and the Firefox Browser with up to 70 Tabs open, which I would attempt to refresh all at once.
The results were staggering.
I won't go into detail, but the important thing to note, is I have 16GB of DDR4 RAM
When Windows would need 15+GB of memory, Linux would only be using about 10GB+. That is a 37.5% - 42.5% gain.
However, I have Windows PRO, this allowed me to disable much of the telemetry, and I found that if I disabled windows telemetry and some other features windows was much more performant. When windows would use 15+ Linux would be at 12+ GB, that's still around a 25-20% gain of memory though.
One important thing to note though, sometime Linux would freeze up on me, windows was more robust at recovering when I overloaded the system, but it took quite a bit less to bog windows down.
...is that your only using 8GB, that's not very much now'a days.
2BH I feel like the 16GB I have is far to little, I plan on upgrading soon.
When troubleshooting, you need to always check that your syntax, and semantics are correct, that way you can rule out that the problem isn't due to a silly typo that you made.
"I know what your thinking..."
"Its not a typo!",
But as it turns out there is a typo: The code snippet you added as part of your question uses the Node Command-line Flag syntax, as the syntax for the Node Environment Variable, this is incorrect, as they use different sets of characters. At first glance, they look identical, but if you look at the 2-part MD table I created below, you'll see there is actually a pretty big difference between the two
SEMANTICS | SYNTAX | DIFFERENCE |
---|---|---|
Command-line Flag | "--max-old-space-size" |
DASHES |
Environment Variable | "--max_old_space_size" |
UNDERSCORES |
"If you used the right syntax and you still are having an issue, you can check to see that the max size of the heap is actually being configured to the size value that you are assigning to it. The process for logging the configured V8 Max Heap Size in the console can be done by completing the stops below."
TO START: Create a completely empty JavaScript file in an environment where you can run it using the node command — name the file test.js.
Add the code below to test.js
, and don't add anything else.
/**
* @file "./test.js"
* @desc "PRINTS: The upper memory limit for V8s HEAP"
* */
const maxHeapSz = require('v8').getHeapStatistics().heap_size_limit;
const maxHeapSz_GB = (maxHeapSz / 1024 ** 3).toFixed(1);
console.log('--------------------------');
console.log(`${maxHeapSz_GB}GB`);
~/$ node --max-old-space-size=8192 test.js; node --max-old-space-size=4096 test.js; node --max-old-space-size=2048 test.js; node --max-old-space-size=1024 test.js; node --max-old-space-size=512 test.js
It would be very strange if you produced a different result than what the editor in the image (my editor) produced, and here is why:
The command above configures the "Max_Old_Space" Env Var. The program that I asked you to "Copy-&-Paste" into the file "test.js" prints the result of the commands Environment configuration change. It shows that every time you set the Env Var to something different, the Env Var is different during "Run Time". Its important to double note, its a variable, an "Environment Variable", it doesn't actually change the size of the heap, the value it represents is just saying that:
_"I the developer approve of the heap growing to the size that is set in the Environment Variable: "MAX_OLD_SPACE_SIZE"
...which does not instantly mean node is able to accomplish such sizes, hell, you could set it to 10e1000 MBs if you wanted, and it would mostly likely accept that number as a valid configuration. I tested all kinds of different stuff, and there is no doubt that you can set it several hundred times more than the amount of ram you actually have. In other words, its a variable, (i.e. an address to a location in memory that holds a binary value), there shouldn't be any issue setting it. It is far more likely that your machine is unable to allocate the amount of space needed, 8GB of RAM, when you only have 16GBs, can be, for some systems, a large amount to offer to a single process, especially f your running Windows, or MacOS. Linux is king in resource intensive situations.
"I assume your on Windows from the image you uploaded into your question, therefore, I will continue to answer this question for Windows only. If you need help with a different platform please let me know by editing your question."
"If this question still is not resolved at this point I will need a bit more info from you, such as the error messages you receive. Also a more in-depth explanation of what is actually happening, for instance, a further more indepth explanation about the statement below would be very helpful. As well as providing the screen shot asked for above"
"unexpected behavior but seems to still be 4GB after hitting CTRL + C"
Upvotes: 9