[BUG] npm install in workspace root installs optional peer dependencies of workspace package dependencies
Nobody has claimed this yet.
- Dominant language
- JavaScript
- Stars
- 10.1k
- Forks
- 4.7k
- Avg merge
- 2d 2h
- Merged PRs (30d)
- 19
Description
Current Behaviour:
See Steps to Reproduce for details.
When running npm install in the root of a project with workspaces configured, duplicate versions of react are installed because npm installs the version that one of my packages depends on directly AND a version of react that is an optional peer dependency of one of my package's dependencies resulting in:
react@16.14.0 is installed in /root/node_modules/react
react@17.0.0 is installed in /root/apps/next-js-app/node_modules/react
Running the app with npm run dev results in React errors from duplicate versions of react
Expected Behavior:
react@17 satisfies my next app's own dependency AND the peer dependency of @apollo/client and thus only:
react@17.0.0 is installed in /root/node_modules/react
Steps To Reproduce:
I've provided the following reproduction example https://github.com/bradbarrow/npm-peer-deps-workspaces
Run npm install in the root of that repository and note the duplicate versions of react with npm list react
OR follow the full reproduction steps below:
- Create a workspace root in
/rootwith a workspace config"workspaces": ["apps/*"] - Create a NextJS app in the
apps/next-js-appdirectory - Add
react@17to thepackage.jsonof the NextJS app - Add
react-dom@17to thepackage.jsonof the NextJS app - Add
@apollo/client@3..3.7to thepackage.jsonof the NextJS app - Note that
@apollo/client@3..3.7has an optionalpeerDependencyof"react": "^16.8.0 || ^17.0.0" - Run
npm installin the root of the project
Environment:
- OS: MacOSX 10.13.6
- Node: 14.15.4
- npm: 7.5.2
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the linked bradbarrow/npm-peer-deps-workspaces reproduction, run npm install at its workspace root, and inspect the result with npm list react. Trace npm's workspace dependency and optional peer-dependency resolution to determine why duplicate React versions are installed; done means the reproduction installs only react@17.0.0 at the root and avoids the duplicate-version errors.
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
- 42/100