title: Node max_old_space_size causes build to fail immediately
body: <p>I am trying to build Mattermost on an armv7a host, but Node is running out of memory during the webpack build.  The solution for this seems to be supposed to set <code>max_old_space_size</code> in <code>NODE_OPTIONS</code>, but counterintuitively doing this seems to cause the build to fail immediately the first time node is run.</p>
  
  <p>The host has 2G of RAM, but I have added 12G of swap to no effect.</p>
  
  <p>CPU:  Marvell Armada 370/XP (Device Tree) (4) @ 1.333GHz</p>
  
  <p>Node:  v13.13.0</p>
  
  <p>Crash when building normally, this occurs after about 30 minutes:</p>
  
  <pre><code>Building mattermost Webapp                                                                                    
  rm -rf dist                                                                                                   
  npm run build                                                                                                                                                                                                               
  
  &gt; mattermost-webapp@0.0.1 build /var/tmp/portage/www-apps/mattermost-server-5.22.0/work/mattermost-server-5.22.0/src/github.com/mattermost/mattermost-server/client                                                         
  &gt; cross-env NODE_ENV=production webpack --display-error-details --verbose                                                                                                                                                   
  
  
  &lt;--- Last few GCs ---&gt;                                                                                        
  
  [17346:0x1e80ee8]  2121678 ms: Mark-sweep 501.2 (506.3) -&gt; 500.7 (506.3) MB, 1640.3 / 0.0 ms  (average mu = 0.108, current mu = 0.029) allocation failure scavenge might not succeed
  [17346:0x1e80ee8]  2123903 ms: Mark-sweep 501.2 (506.3) -&gt; 500.8 (506.3) MB, 2178.0 / 0.0 ms  (average mu = 0.064, current mu = 0.021) allocation failure scavenge might not succeed
  
  
  &lt;--- JS stacktrace ---&gt;                                                                                                                                                                                                     
  
  ==== JS stack trace =========================================                                                                                                                                                               
  
      0: ExitFrame [pc: 0x1468e00]                                                                                                                                                                                            
      1: StubFrame [pc: 0x14098a4]                                                                                                                                                                                            
  Security context: 0x31940491 &lt;JSObject&gt;                                                                                                                                                                                     
      2: /* anonymous */(aka /* anonymous */) [0x9e4bbf89] [/var/tmp/portage/www-apps/mattermost-server-5.22.0/work/mattermost-server-5.22.0/src/github.com/mattermost/mattermost-server/client/node_modules/webpack-sources/l
  ib/applySourceMap.js:~58] [pc=0x9c9a9b44](this=0x40f0027d &lt;undefined&gt;,0x4c40d721 &lt;String[2]: e}&gt;,0xa5f1ebcd &lt;Object ...
  
  FATAL ERROR: Ineffective mark-compacts near heap limit Allocation failed - JavaScript heap out of memory                                                                                                                    
  npm ERR! code ELIFECYCLE                                                                                                                                                                                                    
  npm ERR! errno 1                                                                                                                                                                                                            
  npm ERR! mattermost-webapp@0.0.1 build: `cross-env NODE_ENV=production webpack --display-error-details --verbose`                                                                                                           
  npm ERR! Exit status 1                                                                                                                                                                                                      
  npm ERR!                                                                                                                                                                                                                    
  npm ERR! Failed at the mattermost-webapp@0.0.1 build script.                                                                                                                                                                
  npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
  </code></pre>
  
  <p>Crash when adding <code>NODE_OPTIONS=max_old_space_size=4196</code> (occurs immediately):</p>
  
  <pre><code>make -j4 build                                                                                                                                                                                                              
  Getting dependencies using npm                                                                                                                                                                                              
  npm install                                           
  
  &lt;--- Last few GCs ---&gt;                                                                                                                                                                                                      
  
  [35:0x1ea1e00]      394 ms: Mark-sweep 1.0 (2.5) -&gt; 0.9 (3.5) MB, 10.7 / 0.0 ms  (average mu = 0.724, current mu = 0.096) allocation failure GC in old space requested
  [35:0x1ea1e00]      401 ms: Mark-sweep 0.9 (3.5) -&gt; 0.9 (2.0) MB, 6.6 / 0.0 ms  (average mu = 0.627, current mu = 0.063) last resort GC in old space requested
  [35:0x1ea1e00]      409 ms: Mark-sweep 0.9 (2.0) -&gt; 0.9 (2.0) MB, 8.6 / 0.0 ms  (average mu = 0.463, current mu = 0.005) last resort GC in old space requested
  
  
  &lt;--- JS stacktrace ---&gt;                                                                                       
  
  ==== JS stack trace =========================================
  
      0: ExitFrame [pc: 0x1489e00]
  Security context: 0x375c0491 &lt;JSObject&gt;
      1: test [0x375c4d6d](this=0x5cfb2121 &lt;JSRegExp &lt;String[#14]: (?:^|\/)\.?\.$&gt;&gt;,0x33167c71 &lt;String[#27]: ../lib/utils/unsupported.js&gt;)
      2: /* anonymous */(aka /* anonymous */) [0x375ca1a5] [internal/per_context/primordials.js:23] [bytecode=0x375f6695 offset=28](this=0x4938027d &lt;undefined&gt;,0x5cfb2121 &lt;JSRegExp &lt;String[#14]: (?:^|\/)\.?\.$&gt;&gt;)
      3: arguments adap...
  
  FATAL ERROR: CALL_AND_RETRY_LAST Allocation failed - JavaScript heap out of memory
  make: *** [Makefile:36: node_modules] Aborted
  </code></pre>
  
  <p>Why does changing <code>max_old_space_size</code> cause Node to run out of memory immediately?</p>
  
  <p>Edit: some more information to add...I have been using <a href="https://github.com/Data-Wrangling-with-JavaScript/nodejs-memory-test" rel="nofollow noreferrer">https://github.com/Data-Wrangling-with-JavaScript/nodejs-memory-test</a> as a minimal test case to demonstrate.  It would seem that Node is refusing to consider swap space as usable memory.  For example, if I run:</p>
  
  <pre><code>$ node nodejs-memory-test/index.js
  </code></pre>
  
  <p>It allocates up to the last line:</p>
  
  <pre><code>Allocated since start 0.49 GB
  </code></pre>
  
  <p>before crashing.  If I run:</p>
  
  <pre><code>$ NODE_OPTIONS="--max-old-space-size=1024" node nodejs-memory-test/index.js
  </code></pre>
  
  <p>it successfully runs up to</p>
  
  <pre><code>Allocated since start 0.98 GB
  </code></pre>
  
  <p>before crashing.</p>
  
  <p>However, if I run:</p>
  
  <pre><code>NODE_OPTIONS="--max-old-space-size=8196" node nodejs-memory-test/index.js
  </code></pre>
  
  <p>it only gets through a handful of lines before dying on</p>
  
  <pre><code>Allocated since start 0.01 GB
  </code></pre>
  
  <p>Can somebody help me understand what is going on?</p>