Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

BitBucket Pipelines failing to build production Angular code (staging and local machine working)

I am using BitBucket Pipelines to try to auto-deploy staging and production compiled code. Staging works fine, production works fine on my local server but not on Pipelines. The log of failure is below and I have no clue why it would fail:

"build:prod": "ng build --prod"

+ npm run build:prod
> [email protected] build:prod /opt/atlassian/pipelines/agent/build
> ng build --prod
Browserslist: caniuse-lite is outdated. Please run next command `npm update`
<--- Last few GCs --->
[67:0x3002f10]   220826 ms: Mark-sweep 2014.9 (2069.4) -> 2004.8 (2071.6) MB, 908.6 / 0.1 ms  (average mu = 0.172, current mu = 0.096) allocation failure scavenge might not succeed
[67:0x3002f10]   222095 ms: Mark-sweep 2016.7 (2071.6) -> 2011.3 (2074.4) MB, 1215.6 / 0.1 ms  (average mu = 0.110, current mu = 0.042) allocation failure scavenge might not succeed
FATAL ERROR: Ineffective mark-compacts near heap limit Allocation failed - JavaScript heap out of memory
<--- JS stacktrace --->
==== JS stack trace =========================================
    0: ExitFrame [pc: 0x140a8f9]
Security context: 0x325873d008d1 <JSObject>
    1: join [0x325873d155f9](this=0x1de208ef3a99 <JSArray[11]>,0x20ca5d5b37a1 <String[#1]: />)
    2: computeSourceURL [0x1d3973de0b1] [/opt/atlassian/pipelines/agent/build/node_modules/webpack-sources/node_modules/source-map/lib/util.js:~441] [pc=0x873448f2a77](this=0x0e122b985d01 <Object map = 0x3ff287ea2f39>,0x05b8fbf40731 <String[#0]: >,0x0513ea418d71 <String...
 1: 0xa18150 node::Abort() [ng build --prod]
 2: 0xa1855c node::OnFatalError(char const*, char const*) [ng build --prod]
 3: 0xb9715e v8::Utils::ReportOOMFailure(v8::internal::Isolate*, char const*, bool) [ng build --prod]
 4: 0xb974d9 v8::internal::V8::FatalProcessOutOfMemory(v8::internal::Isolate*, char const*, bool) [ng build --prod]
 5: 0xd54755  [ng build --prod]
 6: 0xd54de6 v8::internal::Heap::RecomputeLimits(v8::internal::GarbageCollector) [ng build --prod]
 7: 0xd616a5 v8::internal::Heap::PerformGarbageCollection(v8::internal::GarbageCollector, v8::GCCallbackFlags) [ng build --prod]
 8: 0xd62555 v8::internal::Heap::CollectGarbage(v8::internal::AllocationSpace, v8::internal::GarbageCollectionReason, v8::GCCallbackFlags) [ng build --prod]
 9: 0xd6500c v8::internal::Heap::AllocateRawWithRetryOrFail(int, v8::internal::AllocationType, v8::internal::AllocationOrigin, v8::internal::AllocationAlignment) [ng build --prod]
10: 0xd2ba2b v8::internal::Factory::NewFillerObject(int, bool, v8::internal::AllocationType, v8::internal::AllocationOrigin) [ng build --prod]
11: 0x106dffe v8::internal::Runtime_AllocateInYoungGeneration(int, unsigned long*, v8::internal::Isolate*) [ng build --prod]
12: 0x140a8f9  [ng build --prod]
Aborted (core dumped)
npm ERR! code ELIFECYCLE
npm ERR! errno 134
npm ERR! [email protected] build:prod: `ng build --prod`
npm ERR! Exit status 134
npm ERR! 
npm ERR! Failed at the [email protected] build:prod script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm ERR! A complete log of this run can be found in:
npm ERR!     /root/.npm/_logs/2021-01-30T19_46_54_147Z-debug.log

This is my bitbucket-pipelines.yml, if it helps:

pipelines:
  custom:
    production:
      - step:
          name: Build an app
          image: node:12.20.1
          deployment: production
          caches:
            - node
          script:
            - npm install
            - npm run build:prod
          artifacts:
            - dist/**

      - step:
          name: Deploy to droplet
          script:
            - rsync -rzO dist/ $SSH_USER@$SSH_SERVER:/home/$WEBSITE/$URL/ --exclude=bitbucket-pipelines.yml

I also tried (one line per attempt), all of them failed:

- node --max_old_space_size=8192 ./node_modules/@angular/cli/bin/ng build --prod
- size: 2x
- ng build --prod
like image 333
Kristjan O. Avatar asked Oct 14 '22 22:10

Kristjan O.


1 Answers

Found this: https://community.atlassian.com/t5/Bitbucket-questions/Bitbucket-Pipeline-fails-with-JavaScript-heap-out-of-memory/qaq-p/732274

Updated my bitbucket-pipelines.yml to this and it's working for now:

pipelines:
  custom:
    production:
      - step:
          name: Build an app
          image: node:12.20.1
          deployment: production
          caches:
            - node
          size: 2x
          script:
            - npm install
            - export NODE_OPTIONS=--max-old-space-size=6144
            - npm run build:prod
          artifacts:
            - dist/**

      - step:
          name: Deploy to droplet
          script:
            - rsync -rzO dist/ $SSH_USER@$SSH_SERVER:/home/$WEBSITE/$URL/ --exclude=bitbucket-pipelines.yml

The app is moderately big, so for now I hope this will work. Not sure what to do if this too starts to fail because of memory issues, once the app grows even more.

like image 136
Kristjan O. Avatar answered Oct 19 '22 00:10

Kristjan O.