[BUG] peerDependencies not preferred over dependencies when both are present
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
Here is a configuration for the styled-components package.json that I'm testing:
The design goal of this is to provide a dependency version specified by us, but allow it to be overridden by peerDependency in client projects if their installed version is greater than ours. Looking at this RFC that was closed as completed, it seems like this is meant to work in npm. However, both versions are currently installed. Here is an example repo demonstrating the current behavior: https://github.com/quantizor/styled-components-repro
I did an analysis of other package managers like yarn and pnpm, and they both seem to honor peerDependencies as an override over dependencies if both are specified in a library being consumed by a client application.
You can see this in action for the supplied reproduction repository by following these instructions after cloning:
- Delete
node_modulesandpackage-lock.json - Run
yarn install - Observe in
node_modules/styled-componentsthat no extranode_modulesfolder is added
Expected Behavior
If a package declared in both dependencies and peerDependencies, peerDependencies should "win" if a compliant higher version is installed in the client application.
Steps To Reproduce
- Clone https://github.com/quantizor/styled-components-repro and
cdinto the directory - Run
npm i - Observe that
node_modules/styled-components/node_moduleshas a duplicated module forpostcss(there is a higher version also installed atnode_modules/postcss)
Environment
- npm: 10.2.5
- Node.js: 18.19.0
- OS Name: macOS
- System Model Name: MacBook Air
- npm config:
; node version = v18.19.0
; npm local prefix = /Users/[redacted]/code/styled-components-repro
; npm version = 10.2.5
; cwd = /Users/[redacted]/code/styled-components-repro
; HOME = /Users/[redacted]
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 package.json configuration and the styled-components-repro repository, then run npm i and inspect node_modules/styled-components/node_modules alongside the top-level node_modules/postcss. Done means a compliant higher peerDependency is used instead of installing a duplicate dependency, matching the behavior described for yarn.
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
- Mostly clear
- Newbie friendliness
- 35/100