berry icon indicating copy to clipboard operation
berry copied to clipboard

[Bug?]: Yarn run issue with node-modules: node linker and nmHoistingLimits: dependencies

Open X-Guardian opened this issue 7 months ago • 0 comments

Self-service

  • [ ] I'd be willing to implement a fix

Describe the bug

With Yarn configured to use nodeLinker: node-modules and nmHoistingLimits: dependencies, when using the yarn run CLI to execute certain binaries, depending upon the root package name, Yarn may error with:

Usage Error: Couldn't find a script named "<binary>".

To reproduce

Initialise a project using the Nx framework with the following script:

corepack enable
yarn init --name 'yarn-test1'
yarn config set nodeLinker node-modules
yarn config set nmHoistingLimits dependencies
yarn add [email protected]
yarn run nx init --nxCloud false
yarn run nx add @nx/[email protected]
yarn run nx add @nx/[email protected]

Run yarn run nx --help and the nx CLI help will be successfully displayed.

Now in package.json, change the name to yarn-test2 and re-run yarn install

Run yarn run nx --help and Yarn will now error with:

Usage Error: Couldn't find a script named "nx".

Environment

System:
    OS: macOS 15.3.2
    CPU: (12) arm64 Apple M2 Pro
  Binaries:
    Node: 22.16.0 - /private/var/folders/pz/q84_my554js504tv_6w4g1gh0000gp/T/xfs-2c256720/node
    Yarn: 4.6.0 - /private/var/folders/pz/q84_my554js504tv_6w4g1gh0000gp/T/xfs-2c256720/yarn
    npm: 10.9.2 - ~/.nvm/versions/node/v22.16.0/bin/npm
    bun: 1.1.42 - /opt/homebrew/bin/bun

Additional context

Certain root package names seem to trigger the issue, here are a selection:

  • yarn-test1 - ok
  • yarn-test2 - error
  • yarn-test3 - ok
  • yarn-test22 - error
  • aaa - ok
  • aaaa - error

etc

I'm suspicious this is to do with an issue with the locator hash logic in the getPackageAccessibleBinaries function.

X-Guardian avatar Jun 06 '25 15:06 X-Guardian