npm / npm/cli

[BUG] Unable to update peer dependencies in workspaces

Open
#4,851 3 comments 1 reaction 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've setup a root package with a single workspace, and in that workspace I've installed React and another dependency that has defined a peer dependency on the same version of React. That version of React gets hoisted to the root node_modules and everything works as expected. If I then try to upgrade React, npm will leave that version intact and install the new version in the nested node_modules inside the workspace, leaving the other dependency using the old version of React with seemingly no way to upgrade it.

Expected Behavior

I would expect that when I upgrade the version of React that I installed, that this would update the version in the root node_modules to also be used by other dependencies that have specified React as a peer dependency, rather than installing a separate version in the nested node_modules for the workspace.

Steps To Reproduce
mkdir workspaces-repro
cd workspaces-repro

npm init -y
npm init -y -w packages/package

npm install react@16 react-dom@16 -w package
npm install -D @testing-library/react@12 -w package

# At this point, everything should be using React 16 from the root node_modules 
npm ls react

npm install react@17 react-dom@17 -w package

# React 17 has now been installed in the node_modules directory inside of the package workspace, and the testing library package is still using React 16 from the root node_modules
npm ls react
Environment
  • npm: 8.8.0
  • Node.js: v16.15.0
  • OS Name: macOS Monterey 12.3.1
  • System Model Name: MacBook Pro
  • npm config:
; node bin location = /Users/james.brooks/.nvm/versions/node/v16.15.0/bin/node
; node version = v16.15.0
; npm local prefix = /Users/james.brooks/Desktop/workspaces-repro
; npm version = 8.8.0
; cwd = /Users/james.brooks/Desktop/workspaces-repro
; HOME = /Users/james.brooks
; Run `npm config ls -l` to show all defaults.

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

Run the provided workspace reproduction with npm 8.8.0 and compare the two npm ls react results. Investigate npm's workspace dependency and peer-dependency resolution, then verify that upgrading React leaves the workspace and peer-dependent package using the expected React version from the root node_modules.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, nodejs
Domain
cli, tooling
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.