berry
berry copied to clipboard
[Bug?]: Yarn run issue with node-modules: node linker and nmHoistingLimits: dependencies
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- okyarn-test2- erroryarn-test3- okyarn-test22- erroraaa- okaaaa- error
etc
I'm suspicious this is to do with an issue with the locator hash logic in the getPackageAccessibleBinaries function.