Skip to content

[Bug]: Regression Yarn 4.3.0->Yarn 4.12.0 : OOM during resolution step — later fails with RangeError: Invalid array length #7047

@aeltorio

Description

@aeltorio

Self-service

  • I'd be willing to implement a fix

Describe the bug

Description

When running yarn install with Yarn 4.12.0 (via Corepack) on a moderately large dependency graph, the process either runs out of memory (OOM) during the resolution step or (when given a very large heap) runs for a long time then fails with RangeError: Invalid array length.

Reproduction repository

https://github.com/sctg-development/yarn-4.12.0-bug

Environment

  • Yarn: 4.12.0 (Corepack downloads this version when prompted)
  • Node: v24.13.3 (LTS)
  • OS: macOS 15.7.3 (Intel)
  • Note: with large heap, observed peak memory ≈ 27 GB; resolution ran ~43 minutes before final failure

Steps to reproduce

  1. Clone the repro:
git clone https://github.com/sctg-development/yarn-4.12.0-bug.git
cd yarn-4.12.0-bug
  1. Run yarn install and accept Corepack's prompt to download Yarn 4.12.0:
yarn install
# When asked: "Do you want to continue? [Y/n]" → press Y
  1. Observe failure (default memory → OOM) or run with a very large heap:
NODE_OPTIONS="--max-old-space-size=64000" yarn install

This runs longer (±43 min) but fails with RangeError: Invalid array length during resolution.

Observed output (excerpts)

OOM (default memory):

➤ YN0000: · Yarn 4.12.0
➤ YN0000: ┌ Resolution step
➤ YN0085: │ + @auth0/auth0-react@npm:2.13.0, @cloudflare/workers-types@npm:4.20260207.0, @heroui/button@npm:2.2.30, @heroui/card@npm:2.2.27, @heroui/checkbox@npm:2.3.30, @heroui/code@npm:2.2.23, @heroui/date-picker@npm:2.3.31, @heroui/dropdown@npm:2.3.30, @heroui/image@npm:2.2.19, and 1230 more.

<--- Last few GCs --->

[7383:0x7f9d10018000]   529831 ms: Scavenge (interleaved) 4069.7 (4080.5) -> 4062.4 (4096.7) MB, pooled: 0 MB, 10.15 / 0.00 ms  (average mu = 0.295, current mu = 0.255) allocation failure; 
[7383:0x7f9d10018000]   530890 ms: Mark-Compact (reduce) 4063.1 (4096.7) -> 4062.5 (4066.2) MB, pooled: 0 MB, 948.01 / 0.00 ms  (+ 49.3 ms in 11 steps since start of marking, biggest step 5.0 ms, walltime since start of marking 1002 ms) (average mu = 0.26
FATAL ERROR: Ineffective mark-compacts near heap limit Allocation failed - JavaScript heap out of memory
----- Native stack trace -----

 1: 0x10f78b6a3 node::OOMErrorHandler(char const*, v8::OOMDetails const&) [/usr/local/bin/node]
 2: 0x10f9bbced v8::internal::V8::FatalProcessOutOfMemory(v8::internal::Isolate*, char const*, v8::OOMDetails const&) [/usr/local/bin/node]
 3: 0x10fc38577 v8::internal::Heap::FatalProcessOutOfMemory(char const*) [/usr/local/bin/node]
 4: 0x10fc3bcba v8::internal::Heap::RecomputeLimits(v8::internal::GarbageCollector, v8::base::TimeTicks) [/usr/local/bin/node]
 5: 0x10fc4fc86 v8::internal::Heap::CollectGarbage(v8::internal::AllocationSpace, v8::internal::GarbageCollectionReason, v8::GCCallbackFlags)::$_1::operator()() const [/usr/local/bin/node]
 6: 0x10fc4f51f void heap::base::Stack::SetMarkerAndCallbackImpl<v8::internal::Heap::CollectGarbage(v8::internal::AllocationSpace, v8::internal::GarbageCollectionReason, v8::GCCallbackFlags)::$_1>(heap::base::Stack*, void*, void const*) [/usr/local/bin/node]
 7: 0x1106d3598 PushAllRegistersAndIterateStack [/usr/local/bin/node]
 8: 0x10fc36019 v8::internal::Heap::CollectGarbage(v8::internal::AllocationSpace, v8::internal::GarbageCollectionReason, v8::GCCallbackFlags) [/usr/local/bin/node]
 9: 0x10fb9e85f v8::internal::StackGuard::HandleInterrupts(v8::internal::StackGuard::InterruptLevel) [/usr/local/bin/node]
10: 0x11012b433 v8::internal::Runtime_StackGuardWithGap(int, unsigned long*, v8::internal::Isolate*) [/usr/local/bin/node]
11: 0x1107d2376 Builtins_CEntry_Return1_ArgvOnStack_NoBuiltinExit [/usr/local/bin/node]
12: 0x12ed4bea1 
zsh: abort      yarn install

With large heap:

➤ YN0000: · Yarn 4.12.0
➤ YN0000: ┌ Resolution step
➤ YN0085: │ + @auth0/auth0-react@npm:2.13.0, @cloudflare/workers-types@npm:4.20260207.0, @heroui/button@npm:2.2.30, @heroui/card@npm:2.2.27, @heroui/checkbox@npm:2.3.30, @heroui/code@npm:2.2.23, @heroui/date-picker@npm:2.3.31, @heroui/dropdown@npm:2.3.30, @heroui/image@npm:2.2.19, and 1230 more.
➤ YN0001: │ RangeError: Invalid array length
    at Array.push (<anonymous>)
    at Q8 (/Users/rlemeill/.cache/node/corepack/v1/yarn/4.12.0/yarn.js:140:112632)
    at hat (/Users/rlemeill/.cache/node/corepack/v1/yarn/4.12.0/yarn.js:206:5630)
    at t.resolveEverything (/Users/rlemeill/.cache/node/corepack/v1/yarn/4.12.0/yarn.js:209:10078)
    at process.processTicksAndRejections (node:internal/process/task_queues:103:5)
    at async /Users/rlemeill/.cache/node/corepack/v1/yarn/4.12.0/yarn.js:212:2645
    at async Ot.startSectionPromise (/Users/rlemeill/.cache/node/corepack/v1/yarn/4.12.0/yarn.js:175:2828)
    at async t.install (/Users/rlemeill/.cache/node/corepack/v1/yarn/4.12.0/yarn.js:212:2584)
    at async /Users/rlemeill/.cache/node/corepack/v1/yarn/4.12.0/yarn.js:462:18229
    at async Ot.start (/Users/rlemeill/.cache/node/corepack/v1/yarn/4.12.0/yarn.js:175:1995)
➤ YN0000: └ Completed in 43m 53s
➤ YN0000: · Failed with errors in 43m 53s

Expected behavior

yarn install completes successfully without exhausting memory or throwing RangeError: Invalid array length.

Workarounds tried

  • Increasing Node heap (NODE_OPTIONS="--max-old-space-size=64000") delays failure but does not prevent RangeError.
  • Tried older Yarn (e.g., corepack prepare yarn@4.9.2 --activate) but same behavior.

Notes / Hypothesis

  • The failure originates in the resolution step (t.resolveEverything) and may involve very large array allocations during dependency resolution.
  • Repro is deterministic for this repo and environment.

To reproduce

  1. Clone the repro:
git clone https://github.com/sctg-development/yarn-4.12.0-bug.git
cd yarn-4.12.0-bug
  1. Run yarn install and accept Corepack's prompt to download Yarn 4.12.0:
yarn install
# When asked: "Do you want to continue? [Y/n]" → press Y
  1. Observe failure (default memory → OOM) or run with a very large heap:
NODE_OPTIONS="--max-old-space-size=64000" yarn install

Environment

System:
    OS: macOS 15.7.3
    CPU: (12) x64 Intel(R) Core(TM) i7-8850H CPU @ 2.60GHz
  Binaries:
    Node: 24.13.0 - /private/var/folders/md/j4y09m6d0vvbt5glr8gn7crh0000gn/T/xfs-947a2244/node
    Yarn: 4.12.0 - /private/var/folders/md/j4y09m6d0vvbt5glr8gn7crh0000gn/T/xfs-947a2244/yarn
    npm: 11.6.2 - /usr/local/bin/npm

Additional context

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions