GeezerVison is showing github.com — fix(exec): prevent shared binPaths pollution across workspace runs by arjun-vegeta · Pull Request #9650 · npm/cli
Conversation
arjun-vegeta
commented
Jun 24, 2026
•
edited by owlstronaut
Loading
Uh oh!
There was an error while loading. Please reload this page.
Description:
related: #9640
Bug:
When running npm exec across multiple workspaces, the binary from the first workspace would accidentally bleed into the second one if they shared the same name.
Root Cause:
In libnpmexec, the binPaths array was scoped at the module level instead of inside the exec() function. Since execWorkspaces runs everything in a single process, binPaths just kept accumulating paths. When the second workspace ran, the first workspace's .bin path was still sitting at the front of PATH, so it hijacked the execution.
Fix:
Moved binPaths inside exec() so it gets a fresh array on every call. I left the manifests map at the module level (keyed by spec.raw) because we still want to cache registry specs across calls, and absolute paths won't collide anyway.
Testing:
- Added a regression test in
test/local.js with two workspaces using the exact same local bin name (shared-bin).
- Gave each test call its own
args array to stop @npmcli/run-script from mutating it and hanging the tests.
- Fails correctly without the fix. With the fix, all tests pass 100%.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for digging into this, but I ran your exact repro on the branch and it still prints A bin / A bin under workspace hoisting only one shared-bin link gets created (→tool-a), so the binPaths change doesn't actually fix #9640
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Fixes npm#9640 by preventing fallback to hoisted .bin directories for workspace packages.
Thanks for digging into this, but I ran your exact repro on the branch and it still prints A bin / A bin under workspace hoisting only one shared-bin link gets created (→tool-a), so the binPaths change doesn't actually fix #9640
Thanks for testing it out. The old binPaths approach was a dead end because of how the hoisted .bin symlink gets overwritten at the root
I just pushed a complete rewrite. I dropped the binPaths idea entirely and instead hooked into the Arborist tree. Now, if it detects it's running inside a workspace, it walks the actual dependency graph (edgesOut) for that specific workspace node to find the correct binary path directly (e.g., node_modules/tool-b/cli.js), completely bypassing the hoisted .bin folder
The repro now outputs A bin / B bin correctly, and I've added full integration tests for the hoisted edge-case. Can you test it out once more and let me know how it goes
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
arjun-vegeta
changed the title
fix(exec): prevent shared binPaths pollution across workspace runs
fix(libnpmexec): correctly resolve workspace dependency binaries from graph
Jun 25, 2026
|
@owlstronaut I think the issue here is the bin-hoisting collision in hoisted mode. For that, we need only the changes from the earlier version of the PR, a6f9044.
Then we can create a separate issue for bin collision.
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
|
Thanks for iterating on this. A few concerns with the graph + node <binFile> approach:
1. It assumes every bin is a Node script. Running the resolved bin as node <binFile> breaks non-node bins — shell scripts, native binaries, or a non-node shebang. The .bin shim path (symlink / cmd-shim) honors the shebang; node <binFile> does not.
2. It bypasses the hoisted .bin for all workspace execs, not just collisions. Any npm exec -w <ws> -- <dep-bin> now runs node <binFile> directly even when the root shim is already correct, a broad behavior change that drops shim/shebang handling for cases that were fine.
3. Same-named bins across multiple direct deps resolve non-deterministically. The first matching edgesOut entry wins, i.e. by package.json order, not by the package that owns the installed shim.
4. The tests mock loadActual() by hand, so they don't verify a real installed tree resolves as assumed.
On scope: the binPaths reset is a valid, separate fix (it makes the linked strategy correct across sequential runs) but doesn't address the hoisted collision on its own. The collision is that npm links only one shared-bin into the shared root .bin (first-wins in bin-links), so no correct per-workspace shim exists. Fixing that cleanly - cross-platform, all bin types - wants a fix at the install layer (arborist creating a per-workspace .bin link on a hoisted name collision), not a special case in libnpmexec.
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
|
Thanks for the review. I'll revert the graph walk and scope this PR back to just the binPaths reset for #9640
I'll dig more into the hoisted bin collision on the arborist/bin-links side and open a separate PR for that
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
…pendencies"
This reverts commit 94a0d84.
arjun-vegeta
changed the title
fix(libnpmexec): correctly resolve workspace dependency binaries from graph
fix(exec): prevent shared binPaths pollution across workspace runs
Jun 27, 2026
Uh oh!
There was an error while loading. Please reload this page.
|
🎉 Backport to release/v11 created: #9692
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Reviewers
1 more reviewer
Reviewers whose approvals may not affect merge requirements
Uh oh!
There was an error while loading. Please reload this page.
Assignees
No one assigned
Milestone
No milestone
Development
Successfully merging this pull request may close these issues.
Uh oh!
There was an error while loading. Please reload this page.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
|