title: Building Angular project lead to heap out of memory
body: <p>When trying to build an Angular project on a Linux server with -aot flag, I get an error. I tried upgrading my instance to a higher CPU core, more RAM and turn on a SWAP partition but still the error just occur faster.</p>
  
  <p>Here's while trying to build from terminal along with the command with the flags I use.</p>
  
  <pre><code>ng build --target=production --environment=prod --aot
  Your global Angular CLI version (1.7.2) is greater than your local
  version (1.4.7). The local Angular CLI version is used.
  
  To disable this warning use "ng set --global warnings.versionMismatch=false".
   10% building modules 5/5 modules 0 activeTemplate parse warnings:                 
  The &lt;template&gt; element is deprecated. Use &lt;ng-template&gt; instead ("
  [WARNING -&gt;]&lt;template [ngIf]="!isClosed"&gt;
    &lt;div [class]="'alert alert-' + type" role="alert" [ngClass]="classes""): ng:///****************node_modules/ngx-bootstrap/alert/alert.component.d.ts.AlertComponent.html@1:0
   92% chunk asset optimization                                                             
  &lt;--- Last few GCs ---&gt;
  
    133611 ms: Mark-sweep 1302.6 (1435.2) -&gt; 1297.8 (1435.2) MB, 1112.6 / 0.0 ms [allocation failure] [GC in old space requested].
    134724 ms: Mark-sweep 1297.8 (1435.2) -&gt; 1297.7 (1435.2) MB, 1112.7 / 0.0 ms [allocation failure] [GC in old space requested].
    135854 ms: Mark-sweep 1297.7 (1435.2) -&gt; 1302.7 (1406.2) MB, 1129.8 / 0.0 ms [last resort gc].
    136983 ms: Mark-sweep 1302.7 (1406.2) -&gt; 1307.9 (1406.2) MB, 1128.8 / 0.0 ms [last resort gc].
  
  
  &lt;--- JS stacktrace ---&gt;
  
  ==== JS stack trace =========================================
  
  Security context: 0xb8bacacfb39 &lt;JS Object&gt;
      1: find_variable [0xb8baca04381 &lt;undefined&gt;:~3539] [pc=0xbdb4151ee32] (this=0xa9144042161 &lt;an AST_Function with map 0xd6ccb950f99&gt;,name=0x1f852792bb29 &lt;String[12]: DOMException&gt;)
      2: visit [0xb8baca04381 &lt;undefined&gt;:3449] [pc=0xbdb4151d969] (this=0x3da6d780b621 &lt;a TreeWalker with map 0xd6ccb9394c9&gt;,node=0x2f9919fb8e91 &lt;an AST_SymbolRef with map 0xd6ccb9628c9&gt;,descend=0x2e68ca83edd1 &lt;JS Fu...
  
  FATAL ERROR: CALL_AND_RETRY_LAST Allocation failed - JavaScript heap out of memory
   1: node::Abort() [ng]
   2: 0x109bf8c [ng]
   3: v8::Utils::ReportApiFailure(char const*, char const*) [ng]
   4: v8::internal::V8::FatalProcessOutOfMemory(char const*, bool) [ng]
   5: v8::internal::Factory::NewInternalizedStringImpl(v8::internal::Handle&lt;v8::internal::String&gt;, int, unsigned int) [ng]
   6: v8::internal::StringTable::LookupString(v8::internal::Isolate*, v8::internal::Handle&lt;v8::internal::String&gt;) [ng]
   7: v8::internal::LookupIterator::PropertyOrElement(v8::internal::Isolate*, v8::internal::Handle&lt;v8::internal::Object&gt;, v8::internal::Handle&lt;v8::internal::Object&gt;, bool*, v8::internal::LookupIterator::Configuration) [ng]
   8: v8::internal::Runtime::GetObjectProperty(v8::internal::Isolate*, v8::internal::Handle&lt;v8::internal::Object&gt;, v8::internal::Handle&lt;v8::internal::Object&gt;) [ng]
   9: 0xed3501 [ng]
  10: v8::internal::Runtime_KeyedGetProperty(int, v8::internal::Object**, v8::internal::Isolate*) [ng]
  11: 0xbdb262092a7
  Aborted (core dumped)
  </code></pre>
  
  <p>I tried the solution mentioned here, <a href="https://www.npmjs.com/package/increase-memory-limit" rel="nofollow noreferrer">https://www.npmjs.com/package/increase-memory-limit</a>
  But still with no luck</p>