title: Node.js Heap out of Memory at build time
body: <p>The build of my React app fails with a (after two days of trials) horrendous 'JavaScript heap out of memory'.</p>
  <p>I've tried the suggestions in many posts including:</p>
  <p><a href="https://stackoverflow.com/questions/38558989/node-js-heap-out-of-memory">This one</a>
  (&quot;many&quot; as &quot;after that tenth try you could say you've tried 'many and any' option).</p>
  <p>But all result in failure.</p>
  <pre><code>&lt;--- Last few GCs ---&gt;
  
  [12207:0x4e75380]   177858 ms: Mark-sweep (reduce) 2044.8 (2080.0) -&gt; 2042.4 (2073.5) MB, 938.5 / 0.1 ms  (+ 350.7 ms in 41 steps since start of marking, biggest step 18.9 ms, walltime since start of marking 1302 ms) (average mu = 0.154, current mu = 0.10[12207:0x4e75380]   177863 ms: Scavenge 2043.5 (2073.5) -&gt; 2042.6 (2074.5) MB, 2.6 / 0.0 ms  (average mu = 0.154, current mu = 0.103) allocation failure 
  
  
  &lt;--- JS stacktrace ---&gt;
  
  FATAL ERROR: Ineffective mark-compacts near heap limit Allocation failed - JavaScript heap out of memory
   1: 0xb200e0 node::Abort() [node]
   2: 0xa3c157 node::FatalError(char const*, char const*) [node]
   3: 0xd083ae v8::Utils::ReportOOMFailure(v8::internal::Isolate*, char const*, bool) [node]
   4: 0xd08727 v8::internal::V8::FatalProcessOutOfMemory(v8::internal::Isolate*, char const*, bool) [node]
   5: 0xee9785  [node]
   6: 0xeea2cc  [node]
   7: 0xef8269 v8::internal::Heap::CollectGarbage(v8::internal::AllocationSpace, v8::internal::GarbageCollectionReason, v8::GCCallbackFlags) [node]
   8: 0xefb5ac v8::internal::Heap::AllocateRawWithRetryOrFailSlowPath(int, v8::internal::AllocationType, v8::internal::AllocationOrigin, v8::internal::AllocationAlignment) [node]
   9: 0xec000c v8::internal::Factory::NewFillerObject(int, bool, v8::internal::AllocationType, v8::internal::AllocationOrigin) [node]
  10: 0x123695b v8::internal::Runtime_AllocateInYoungGeneration(int, unsigned long*, v8::internal::Isolate*) [node]
  11: 0x1640839  [node]
  </code></pre>
  <p>The weird part is the same project fails to load some package inside some of Firebase dependencies, google-gax.</p>
  <p><a href="https://i.stack.imgur.com/Eq89M.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Eq89M.png" alt="not found" /></a></p>
  <p>caused by (presumably) bad 'require' calling</p>
  <p><a href="https://i.stack.imgur.com/M4aS3.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/M4aS3.png" alt="this is unbelievable!" /></a></p>
  <p>could the memory error be related to this google package &quot;misspelling&quot;. A reflect of something being hidden out there in the project.</p>
  <p>P.D.: This error only happens in this branch. Other branches of the same project don't fail.</p>
  <p>P.D.: The google-gax bad require mut be corrected (manually) in order to compile (or try to do so) the project.</p>