npm / npm/cli

[BUG] npm prune doesn't work if multiple packages depend on the same module (but different versions)

Open
#4,345 4 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Bug Priority 2 Release 8.x
Dominant language
JavaScript
Stars
10.1k
Forks
4.7k
Avg merge
2d 2h
Merged PRs (30d)
19

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

I have a workspace with foo and bar. Foo depends on react@17 as a dev dep and bar depends on react@16 as a dep. I can npm install just fine, but when I run prune it doesn't remove the react@17 from foo. I've tried many incantations with workspace related flags and whatnot, does not seem to change anything: npm prune --production -ws

Expected Behavior

I would expect that foo's version of react is pruned since it is a dev dep.

Steps To Reproduce
  1. Make a workspace with two subprojects: foo, bar
  2. npm install react@16 -w bar
  3. npm install -D react@17 -w foo
  4. npm prune --production -ws
  5. Check node modules and see that react 17 is still there
Environment
  • npm: 8.4.0
  • Node.js: 16.13.1
  • OS Name: OSX
  • System Model Name: MacBook Pro
  • npm config:
; "user" config from /Users/zach/.npmrc

//registry.npmjs.org/:_authToken = (protected) 
yoga-layout:platform = "standalone" 

; "env" config from environment

prefix = "/Users/zach/.asdf/installs/nodejs/lts/.npm" 

; node bin location = /Users/zach/.asdf/installs/nodejs/16.13.1/bin/node
; cwd = /Users/zach
; HOME = /Users/zach

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the workspace setup with foo, bar, react@16, and react@17, then run npm prune --production -ws and inspect npm's workspace pruning and dependency-resolution behavior. Done means the dev-only react@17 installation is removed while bar's react@16 dependency remains.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, node.js
Domain
cli, tooling
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.