[BUG] peerDependency package version doesn't resolve correctly
Nobody has claimed this yet.
- 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
Let's take a simple package.json
{
"name": "untitled",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"react-scripts": "4.0.3",
"worker-loader": "2.0.0"
}
}
react-scripts and worker-loader both have webpack listed in their dependencies or peerDependencies
worker-loader has it listed as
"peerDependencies": {
"webpack": "^3.0.0 || ^4.0.0-alpha.0 || ^4.0.0"
}
react-scripts:
"dependencies": {
"webpack": "4.44.2",
}
The final resolved version of webpack in project's root node_modules will be "4.46.0", and react-scripts will install webpack 4.42.0 in its own node_modules.
If we change peerDependencies of worker-loader to be
"peerDependencies": {
"webpack": "^3.0.0 || ^4.0.0"
}
or change worker-loader version in our root project's package.json to be 3.0.8 (this version has webpack version in peerDependencies listed as as "webpack": "^4.0.0 || ^5.0.0")
In this case, webpack in the project's root directory will be resolved as 4.44.2, and react-scripts won't install another version of webpack in its own node_modules (since 4.44.2 is now shared between two packages)
Expected Behavior
I would expect that in all 3 cases mentioned, webpack should be resolved to 4.44.2 and shared between two packages, or at least the behavior should be consistent.
Steps To Reproduce
- Windows,
npm 8.1.0or higher (haven't tried on previous versions)
create bare-bone project and follow steps mentioned in "Current behavior"
Environment
- npm: 8.1.0 or higher
- Node.js: 16.12.0
- OS Name: Windows
- System Model Name:
- npm config:
; copy and paste output from `npm config ls` here
; "user" config from C:\Users\mixei.npmrc
msvs_version = "2017"
; node bin location = C:\Program Files\nodejs\node.exe
; cwd = C:\Users\mixei\WebstormProjects\untitled
; HOME = C:\Users\mixei
; Run npm config ls -l to show all defaults.
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 by reproducing the package.json example with npm 8.1.0 or higher, Node.js 16.12.0, and Windows, then compare the dependency tree for webpack. No repository files or tests are named; done means the three dependency scenarios resolve webpack consistently as described in the expected behavior.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript, node.js
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100