npm / npm/cli

[BUG] npm install silently fails to install peer dependency

Open
#6,071 0 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

npm doesn't install peer dependency @mdx-js/react without any error or even warning. Warning is printed out only after installation when using npm ci and and in such case @mdx-js/react is also not installed:
image
This happens because npm installs the latest version of React instead version required by dependencies. Such behaviour can be avoided by adding required version of React within package.json. The only reference to a new version of React I found is in library @figspec/react in devDependencies what shouldn't impact.
This issue can be reproduced with the following versions of npm: 8.19.2, 8.19.3, 9.2.0.
package.zip

Expected Behavior

npm should not install the latest version of React but one which is required by dependencies or npm should throw an error when library is not installed.

Steps To Reproduce
  1. In this environment with the latest version of node and npm
  2. With this attached package.json
  3. Run 'npm i'
  4. See node_modules and look for @mdx-js/react
  5. Run 'npm ci'
  6. See warning mesages about problems with resolving dependencies with @mdx-js/react
  7. See node_modules and look for @mdx-js/react
Environment
  • npm: 9.2.0
  • Node.js: 19.4.0
  • OS Name: Microsoft Windows [Version 10.0.19044.2486]
  • System Model Name: Asus G551JM
  • npm config:
; "builtin" config from C:\Program Files\nodejs\node_modules\npm\npmrc

prefix = "C:\\Users\\Radosław\\AppData\\Roaming\\npm"

; "cli" config from command line options

location = "project"

; node bin location = C:\Program Files\nodejs\node.exe
; node version = v19.4.0
; npm local prefix = C:\_projects\test-npm
; npm version = 9.2.0
; cwd = C:\_projects\test-npm
; HOME = C:\Users\Radosław
; 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

Start with the attached package.json from package.zip and reproduce the behavior using npm i and npm ci on the reported Node.js and npm versions. Trace the peer-dependency resolution path responsible for @mdx-js/react and compare the installed dependency tree and warnings; done means the dependency is installed or a clear error is reported consistently.

Written by the indexing model from the issue text.

Assessment

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.