Any way to fix this out of memory error installing @salesforce/sfdx-scanner

continuous-integrationgithub-actionssalesforcedxsfdx-plugin

We run our CI (Continuous Integration) build for our app using GitHub actions and part of that is to install and run the Salesforce CLI Scanner. We run on ubuntu-latest that is documented to have "7 GB of RAM memory".

But starting late yesterday, the install sfdx plugins:install @salesforce/sfdx-scanner is failing with this JavaScript out of memory error:

FATAL ERROR: Ineffective mark-compacts near heap limit Allocation failed - JavaScript heap out of memory
 1: 0xb00d90 node::Abort() [/home/runner/sfdx/bin/node]
 2: 0xa1823b node::FatalError(char const*, char const*) [/home/runner/sfdx/bin/node]
 3: 0xcedbce v8::Utils::ReportOOMFailure(v8::internal::Isolate*, char const*, bool) [/home/runner/sfdx/bin/node]
 4: 0xcedf47 v8::internal::V8::FatalProcessOutOfMemory(v8::internal::Isolate*, char const*, bool) [/home/runner/sfdx/bin/node]
 5: 0xea6105  [/home/runner/sfdx/bin/node]
 6: 0xea6be6  [/home/runner/sfdx/bin/node]
 7: 0xeb4b1e  [/home/runner/sfdx/bin/node]
 8: 0xeb5560 v8::internal::Heap::CollectGarbage(v8::internal::AllocationSpace, v8::internal::GarbageCollectionReason, v8::GCCallbackFlags) [/home/runner/sfdx/bin/node]
 9: 0xeb8455 v8::internal::Heap::HandleGCRequest() [/home/runner/sfdx/bin/node]
10: 0xe459c7 v8::internal::StackGuard::HandleInterrupts() [/home/runner/sfdx/bin/node]
11: 0x11f2655 v8::internal::Runtime_StackGuard(int, unsigned long*, v8::internal::Isolate*) [/home/runner/sfdx/bin/node]
12: 0x15e7819  [/home/runner/sfdx/bin/node]
    Error: yarn add @salesforce/sfdx-scanner@latest --non-interactive 
    --mutex=file:/home/runner/.local/share/sfdx/yarn.lock 
    --preferred-cache-folder=/home/runner/.cache/sfdx/yarn --check-files 
    exited with code null

Any insight or advice on how to fix appreciated.

PS

Adding this export NODE_OPTIONS=--max_old_space_size=4096 to give Node more memory didn't help.

Best Answer

Edit: This has been fixed. You should see no error installing plugins now


This is a noted issue that isn't specific to sfdx-scanner, but installing plugins. Based on info in that issue, it seems the root cause is this current bug in yarn that oclif uses to install plugins. There's a created issue for oclif as well.

There's a fix in the works, but doesn't seem to mention a timeline.

On my end, your command actually worked fine but I see the error with all other plugins I attempted.

It does seem a current workaround can be building it locally until the above is fixed.

  1. Clone sfdx-scanner through git

git clone https://github.com/forcedotcom/sfdx-scanner.git

  1. Build it using yarn
cd sfdx-scanner
yarn --ignore-scripts && yarn build
  1. Then, link the module to sfdx

sfdx plugins: link .