npm / npm/cli

[BUG] Unable to install untracked peer optional dependency

Open
#8,464 10 comments 5 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Bug Priority 2
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 i <dependency name> succeeds with exit code 0 but the resultant dependency is not present, if <dependency name> is an untracked (not included in prod or dev dependencies) optional peer dependency.

I believe this is caused by https://github.com/npm/cli/pull/8431.

Expected Behavior

npm i <dependency name> should always install the dependency if the dependency has no version incompatibility issues.

Steps To Reproduce

Easiest way to see this is working in the mongodb package, because this scenario arose in our CI.

  1. Clone node-mongodb-native.
  2. run npm i
  3. install kerberos: npm i kerberos
  4. attempt to use kerberos: `node -p "require('kerberos')":
node:internal/modules/cjs/loader:1408
  throw err;
  ^

Error: Cannot find module 'kerberos'
Environment
  • npm: 11.5.0+
  • Node.js: doesn't matter
  • OS Name: doesn't matter
  • System Model Name: doesn't matter
  • npm config: doesn't matter

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

Reproduce in the node-mongodb-native package by running npm i, then npm i kerberos, followed by node -p "require('kerberos')". Trace npm 11.5.0's dependency installation and optional peer handling; done means an untracked optional peer dependency is present and can be required when no version incompatibility exists.

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.