0

I am trying to make a build of my angular application on 1vCPU and 1GB memory machine, ]it worked fine at start but as project is getting bigger, it fails with the error "Javascript heap out of memory" But, when aot=false is set, it works fine. Below is the complete detail -

At the start of the Angular, deployment with below command was working fine.

ng build

Then after new components started to add on, it started failing with "Javascript heap out of memory". So changed the 'scripts' > 'build' value in package json to -

"build": "node --max_old_space_size=8192 node_modules/@angular/cli/bin/ng build --configuration=prod"

It worked for sometime, but build start to fail again wth error -

FATAL ERROR: Ineffective mark-compacts near heap limit Allocation failed - JavaScript heap out of memory
 1: 0xa1a640 node::Abort() [ng build --prod]
 2: 0xa1aa4c node::OnFatalError(char const*, char const*) [ng build --prod]
 3: 0xb9a62e v8::Utils::ReportOOMFailure(v8::internal::Isolate*, char const*, bool) [ng build --prod]
 4: 0xb9a9a9 v8::internal::V8::FatalProcessOutOfMemory(v8::internal::Isolate*, char const*, bool) [ng build --prod]
 5: 0xd57c25  [ng build --prod]
 6: 0xd582b6 v8::internal::Heap::RecomputeLimits(v8::internal::GarbageCollector) [ng build --prod]
 7: 0xd64b75 v8::internal::Heap::PerformGarbageCollection(v8::internal::GarbageCollector, v8::GCCallbackFlags) [ng build --prod]
 8: 0xd65a25 v8::internal::Heap::CollectGarbage(v8::internal::AllocationSpace, v8::internal::GarbageCollectionReason, v8::GCCallbackFlags) [ng build --prod]
 9: 0xd684dc v8::internal::Heap::AllocateRawWithRetryOrFail(int, v8::internal::AllocationType, v8::internal::AllocationOrigin, v8::internal::AllocationAlignment) [ng build --prod]
10: 0xd2eefb v8::internal::Factory::NewFillerObject(int, bool, v8::internal::AllocationType, v8::internal::AllocationOrigin) [ng build --prod]
11: 0x10714ce v8::internal::Runtime_AllocateInYoungGeneration(int, unsigned long*, v8::internal::Isolate*) [ng build --prod]
12: 0x140dc19  [ng build --prod]
Aborted (core dumped)

So through multiple sites, I tried below command and it worked fine

ng build --aot=false

Server output -

Output :
Initial Chunk Files | Names         |      Size
vendor.js           | vendor        |   6.81 MB
main.js             | main          | 809.57 kB
styles.css          | styles        | 428.40 kB
polyfills.js        | polyfills     | 239.18 kB
scripts.js          | scripts       | 145.27 kB
runtime.js          | runtime       |   6.15 kB

But, I want the code to complied before, so setting aot=false should not be the permanent solution. Can anyone help me with what I should do, to solve this issue permanently.

Below are the other specifications that I am working with Angular/cli - 11.2.14 Typescript - 4.1.6

Angular.json file -

"build": {
  "builder": "@angular-devkit/build-angular:browser",
  "options": {
    ...
    "aot": true,
    ...
  },
  ...
  "configurations": {
    "production": {
      "optimization": true,
      "outputHashing": "all",
      "sourceMap": false,
      "namedChunks": false,
      "extractLicenses": true,
      "vendorChunk": false,
      "buildOptimizer": true
    }
  }
}

Server specs: vCPUs - 1 memory - 1GiB

Charmi
  • 15
  • 5
  • Will lazy loading be helpful? or do I need to increase the server specifications? – Charmi Mar 13 '23 at 18:43
  • Implemented lazy loading. So the deployment works fine with aot=true. But still gets killed when try to deploy with productionized build i.e. --prod – Charmi Mar 25 '23 at 12:07
  • Finally increased the server specs to run the optimized build – Charmi Apr 24 '23 at 08:21

0 Answers0