cli: yarn add netlify-cli fails with "JavaScript heap out of memory"

Describe the bug

FATAL ERROR: Ineffective mark-compacts near heap limit Allocation failed - JavaScript heap out of memory occurs when adding netlify-cli with yarn.

Originally identified on the forums https://answers.netlify.com/t/error-adding-netlify-cli-with-yarn/48579

To Reproduce

Steps to reproduce the behavior:

  1. Run yarn add netlify-cli

Configuration

% npx envinfo --system --binaries --npmPackages netlify-cli --npmGlobalPackages netlify-cli

  System:
    OS: macOS 12.0.1
    CPU: (12) x64 Intel(R) Core(TM) i5-10600 CPU @ 3.30GHz
    Memory: 1.76 GB / 16.00 GB
    Shell: 5.8 - /bin/zsh
  Binaries:
    Node: 16.13.1 - /usr/local/bin/node
    Yarn: 1.22.17 - /usr/local/bin/yarn
    npm: 8.1.2 - /usr/local/bin/npm
  npmPackages:
    netlify-cli: ^8.0.19 => 8.0.19
  npmGlobalPackages:
    netlify-cli: 8.0.19

Expected behavior

Install to not error

CLI Output

% yarn add netlify-cli
yarn add v1.22.17
info No lockfile found.
[1/4] 🔍  Resolving packages...
warning netlify-cli > @netlify/plugin-edge-handlers > rollup-plugin-node-polyfills > rollup-plugin-inject@3.0.2: This package has been deprecated and is no longer maintained. Please use @rollup/plugin-inject.
warning netlify-cli > @netlify/zip-it-and-ship-it > @vercel/nft > node-pre-gyp@0.13.0: Please upgrade to @mapbox/node-pre-gyp: the non-scoped node-pre-gyp package is deprecated and only the @mapbox scoped package will recieve updates in the future
warning netlify-cli > @netlify/zip-it-and-ship-it > precinct > detective-postcss > postcss-values-parser > flatten@1.0.3: flatten is deprecated in favor of utility frameworks such as lodash.
warning netlify-cli > copy-template-dir > readdirp > micromatch > snapdragon > source-map-resolve > resolve-url@0.2.1: https://github.com/lydell/resolve-url#deprecated
warning netlify-cli > copy-template-dir > readdirp > micromatch > snapdragon > source-map-resolve > urix@0.1.0: Please see https://github.com/lydell/urix#deprecated
[2/4] đźšš  Fetching packages...
[3/4] đź”—  Linking dependencies...
warning "netlify-cli > @netlify/build > ts-node@10.4.0" has unmet peer dependency "@types/node@*".
warning "netlify-cli > @netlify/build > ts-node@10.4.0" has unmet peer dependency "typescript@>=2.7".

<--- Last few GCs --->

[2325:0x7fe856200000]    99973 ms: Scavenge 4013.0 (4122.8) -> 4006.9 (4123.8) MB, 21.9 / 0.0 ms  (average mu = 0.126, current mu = 0.054) allocation failure
[2325:0x7fe856200000]   100005 ms: Scavenge 4016.2 (4123.8) -> 4010.8 (4128.8) MB, 8.5 / 0.0 ms  (average mu = 0.126, current mu = 0.054) allocation failure
[2325:0x7fe856200000]   100694 ms: Mark-sweep 4021.5 (4128.8) -> 4011.8 (4135.6) MB, 666.7 / 0.0 ms  (average mu = 0.185, current mu = 0.231) allocation failure scavenge might not succeed


<--- JS stacktrace --->

FATAL ERROR: Ineffective mark-compacts near heap limit Allocation failed - JavaScript heap out of memory
 1: 0x10e767225 node::Abort() [/usr/local/bin/node]
 2: 0x10e7673a8 node::OnFatalError(char const*, char const*) [/usr/local/bin/node]
 3: 0x10e8de9c7 v8::Utils::ReportOOMFailure(v8::internal::Isolate*, char const*, bool) [/usr/local/bin/node]
 4: 0x10e8de963 v8::internal::V8::FatalProcessOutOfMemory(v8::internal::Isolate*, char const*, bool) [/usr/local/bin/node]
 5: 0x10ea7cfe5 v8::internal::Heap::FatalProcessOutOfMemory(char const*) [/usr/local/bin/node]
 6: 0x10ea8100b v8::internal::Heap::RecomputeLimits(v8::internal::GarbageCollector) [/usr/local/bin/node]
 7: 0x10ea7d8ec v8::internal::Heap::PerformGarbageCollection(v8::internal::GarbageCollector, v8::GCCallbackFlags) [/usr/local/bin/node]
 8: 0x10ea7ad9a v8::internal::Heap::CollectGarbage(v8::internal::AllocationSpace, v8::internal::GarbageCollectionReason, v8::GCCallbackFlags) [/usr/local/bin/node]
 9: 0x10ea880f0 v8::internal::Heap::AllocateRawWithLightRetrySlowPath(int, v8::internal::AllocationType, v8::internal::AllocationOrigin, v8::internal::AllocationAlignment) [/usr/local/bin/node]
10: 0x10ea88171 v8::internal::Heap::AllocateRawWithRetryOrFailSlowPath(int, v8::internal::AllocationType, v8::internal::AllocationOrigin, v8::internal::AllocationAlignment) [/usr/local/bin/node]
11: 0x10ea550c7 v8::internal::Factory::NewFillerObject(int, bool, v8::internal::AllocationType, v8::internal::AllocationOrigin) [/usr/local/bin/node]
12: 0x10ee010ae v8::internal::Runtime_AllocateInYoungGeneration(int, unsigned long*, v8::internal::Isolate*) [/usr/local/bin/node]
13: 0x10f1a30b9 Builtins_CEntry_Return1_DontSaveFPRegs_ArgvOnStack_NoBuiltinExit [/usr/local/bin/node]
14: 0x10f1b9056 Builtins_ArrayPrototypeJoin [/usr/local/bin/node]
zsh: abort      yarn add netlify-cli

Additional context

Works with npm add netlify-cli

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Reactions: 5
  • Comments: 19 (7 by maintainers)

Most upvoted comments

Hi all đź‘‹ For those who are installing the CLI locally, can you try adding the following to your package.json:

"resolutions": {
    "@oclif/plugin-help": "3.2.14"
  },

This will pin one of the CLI’s dependencies when installing with yarn and should work around the issue. We’re working on publishing a new version of netlify-cli with this fix as well.

I can also confirm that this fixes the issue for our site on Netlify. It’s odd because we’ve been using the same Yarn version for months without hitting this issue.

Hi all đź‘‹ For those who are installing the CLI locally, can you try adding the following to your package.json:

"resolutions": {
    "@oclif/plugin-help": "3.2.14"
  },

This will pin one of the CLI’s dependencies when installing with yarn and should work around the issue. We’re working on publishing a new version of netlify-cli with this fix as well.

Thanks for the follow up @RodEsp! I can confirm the installation goes through now with yarn add netlify-cli.

Closing this issue. Please comment if this issue has not been resolved for you.

FYI we are tracking this at the oclif level here: oclif/oclif#758

@erezrokah I’ve tested locally with an empty folder and fresh package.json.

I confirm that the install completes successfully with the provided resolution, (and that it still fails if I remove it).

This is currently being escalated as it is causing deployment failures for builds which require netlify-cli in many CI/CD pipelines (including GitHub Actions and Netlify itself). We will an update about this very soon.

Even with

"resolutions": {
    "@oclif/plugin-help": "3.2.14"
  },

in my package.json I still get the error. Here is the output: Screenshot from 2022-01-09 10-41-56

OS:

NAME="elementary OS"
VERSION="5.1.7 Hera"
ID=elementary
ID_LIKE=ubuntu
PRETTY_NAME="elementary OS 5.1.7 Hera"
LOGO=distributor-logo
VERSION_ID="5.1.7"
Yarn 1.22.17
Node v16.13.1

Looks like this is related https://github.com/netlify/cli/issues/3981#issue-1097159039

There is a temporary fix out there for this now, please see https://github.com/oclif/oclif/issues/758#issue-1076987354 for more details.

Hello all 👋 We’re actively looking into this. The current workaround is using npm, and if you’re using a global install this shouldn’t be a big change.

@kirillgroshkov this is happening on very old yarn + CLI versions too, and with other packages (see https://github.com/yarnpkg/yarn/issues/8734), so not sure this was caused by a CLI change.

It turns out that this is an issue in yarn itself:

https://github.com/yarnpkg/yarn/issues/8734

I have tested in an Ubuntu VM with 4 GiB of memory and I can consistently reproduce this error with yarn install. I used the same package JSON for both yarn and npm and all tests used the node version in this report - 16.13.1.

Yarn always returns the JavaScript heap out of memory error while npm install is successful. This happens even with a netlify-cli release from eight days ago (version 8.0.10).

To summarize, this appears to be a yarn bug and not a netlify-cli bug.