Skip to content

fix(js): include workspace member node_modules in install sandbox#23342

Open
jcrobak wants to merge 1 commit into
pantsbuild:mainfrom
jcrobak:fix/js-workspace-member-node-modules
Open

fix(js): include workspace member node_modules in install sandbox#23342
jcrobak wants to merge 1 commit into
pantsbuild:mainfrom
jcrobak:fix/js-workspace-member-node-modules

Conversation

@jcrobak
Copy link
Copy Markdown
Contributor

@jcrobak jcrobak commented May 9, 2026

Problem

In a nodejs workspace, each project of the workspace can have its own node_modules directory that is populated during installation. Previously, pants was capturing the project's workspace and the top-level workspace but not sibling or descendent projects. This caused certain operations to fail, such as tsc --build on a pnpm workspace project since a pnpm project doesn't hoist member deps to the root by default. Outside of pnpm, there are reports of this causing problems with yarn/npm projects where a version conflict prevents hoisting.

Solution

In node_modules_directories, the install sandbox now captures every workspace member's node_modules/, not just the build target's.

Note: the new behavior only impacts the install path ( when self.package is set). Lockfile generation's codepath (viaNodeJsProjectEnvironment.from_root()) doesn't set self.package and keeps the "root only" behavior. Dropping the if self.package check would align with the approach from #23264, but I left out that change to minimize the scope. I added a test to demonstrate this behavior.

References

AI Disclosure

Claude Code was used to diagnose the problem, write the fix with my input, and write
the regression tests

Fixes JavaScript workspace builds where dependencies are installed under
members' node_modules/. The install sandbox now captures every workspace
member's node_modules/, not just the build target's. This fixes pnpm
workspaces in pants and also fixes npm/yarn workspaces when a version
conflict prevented hoisting.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant