-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Description
Is there an existing issue for this?
- I have searched the existing issues
This issue exists in the latest npm version
- I am using the latest npm
Current Behavior
When using npm install --omit=dev with installStrategy: linked in a monorepo, dev dependencies declared in the root package.json are still symlinked into root's node_modules/ in two cases:
- External packages that are both a root devDependency and a production dependency (direct or transitive) of a workspace. The package correctly goes into the store (the workspace needs it), but root incorrectly gets a symlink to it.
- Workspaces declared as root devDependencies (e.g.
@wordpress/buildin Gutenberg) are always hoisted to root'snode_modules/regardless of--omit=dev.
Dev dependencies that are only referenced as devDependencies (not shared with any workspace prod dep) are correctly omitted by the existing fix in PR #9066.
Expected Behavior
With --omit=dev, root's devDependencies should not be symlinked into root's node_modules/, even if the same packages are needed by workspaces as production dependencies. The packages should still be in the store (since workspaces need them), but root should not link to them.
Steps To Reproduce
- Create a monorepo with linked install strategy:
// package.json
{
"name": "myapp",
"workspaces": ["packages/*"],
"dependencies": { "which": "1.0.0" },
"devDependencies": { "typescript": "5.0.0" }
}// packages/mylib/package.json
{
"name": "mylib",
"dependencies": { "typescript": "5.0.0" }
}- Add
.npmrcwithinstall-strategy=linked - Run
npm install --omit=dev - Observe that
typescriptis symlinked in rootnode_modules/despite being a root devDependency
This also affects workspaces declared as root devDependencies (e.g. @wordpress/build in Gutenberg). Even with --omit=dev, these workspaces get symlinked into root's node_modules/ because npm auto-creates workspace type edges (not dev edges) and #rootDeclaredDeps unconditionally includes devDependencies keys.
Environment
- npm: v10 and v11 (latest) -- both affected
- Node.js: v22.20.0
- OS Name: macOS (Darwin)
- npm config:
install-strategy=linked