npm / npm/cli

[BUG] Invalid packages when scoped overrides are used butby a different package

Open
#7,087 0 comments 3 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Bug config:overrides 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 install gives invalid package-lock.json when scoped overrides are used but project contains another dependency that uses it.
npm ls doesn't even show the culprit.

Expected Behavior

npm install should not give invalid packages when scoped overrides are used but project contains another dependency that uses it.
npm ls should be able to find and list the offending the package.

Steps To Reproduce
  1. In an empty folder, create a package.json with the contents:
{
  "name": "abc",
  "version": "1.2.3",
  "description": "",
  "main": "index.js",
  "scripts": {
    "test": "echo 'Hi' && exit 1"
  },
  "author": "",
  "license": "MIT",
  "devDependencies": {
    "lerna": "4.0.0"
  },
  "dependencies": {
    "highcharts-export-server": "^2.1.0"
  },
  "overrides": {
    "highcharts-export-server": {
      "request": {
        "tough-cookie": "4.1.3"
      }
    }
  }
}
  1. npm install.
  2. Run npm ls tough-cookie:
❯ npm ls tough-cookie
npm ERR! code ELSPROBLEMS
npm ERR! invalid: tough-cookie@4.1.3 /Users/<username>/<path>/node_modules/tough-cookie
abc@1.2.3 /Users/<username>/<path>
└─┬ highcharts-export-server@2.1.0 overridden
  ├─┬ phantomjs-prebuilt@2.1.14
  │ └─┬ request@2.79.0 overridden
  │   └── tough-cookie@4.1.3 deduped invalid: "~2.5.0" from node_modules/request
  └─┬ request@2.88.2
    └── tough-cookie@4.1.3 invalid: "~2.5.0" from node_modules/request


npm ERR! A complete log of this run can be found in:

Notice the errors but there is no mention of lerna.
4. Remove lerna 4.0 or change it to lerna 5.0 which doesn't use request and repeat above steps. Notice there are no issues this time.

Environment
  • npm: 10.1.0
  • Node.js: 20.8.1
  • OS Name: Mac OS Sonoma 14.2
  • System Model Name: Macbook Pro - Intel i9
  • npm config:
; "user" config from /Users/<username>/.npmrc

registry = "https://registry.npmjs.org/"

; node bin location = /Users/<username>/n/bin/node
; node version = v20.8.1
; npm local prefix = /Users/<username>/<path>
; npm version = 10.1.0
; cwd = /Users/<username>/<path>
; HOME = /Users/<username>
; 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

Reproduce the problem from the package.json example by running npm install and npm ls tough-cookie, then compare the dependency trees with and without lerna 4.0.0. Done means npm install no longer produces invalid packages and npm ls identifies the dependency causing the incompatible tough-cookie requirement.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, nodejs
Domain
cli
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.