[BUG] npm install fails on scoped package override with cryptic "Invalid comparator" error
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
We have a package override in our project that's working OK in NPM 8 (after some workarounds for https://github.com/npm/cli/issues/5007):
"overrides": {
"pgsql-ast-parser": "@grid-is/pgsql-ast-parser@^111.0.0"
},
Upgrading npm to 9.1.1 or 9.2.0 makes npm install fail in this project, with:
npm ERR! Invalid comparator: @grid-is/pgsql-ast-parser@^111.0.0
and in the debug logfile:
35 verbose shrinkwrap failed to load node_modules/.package-lock.json out of date, updated: node_modules/@grid-is/pgsql-ast-parser
36 timing idealTree Completed in 1300ms
37 timing command:i Completed in 1305ms
38 verbose stack TypeError: Invalid comparator: @grid-is/pgsql-ast-parser@^111.0.0
38 verbose stack at Comparator.parse (/Users/gthb/.nvm/versions/node/v16.18.0/lib/node_modules/npm/node_modules/semver/classes/comparator.js:38:13)
38 verbose stack at new Comparator (/Users/gthb/.nvm/versions/node/v16.18.0/lib/node_modules/npm/node_modules/semver/classes/comparator.js:22:10)
38 verbose stack at /Users/gthb/.nvm/versions/node/v16.18.0/lib/node_modules/npm/node_modules/semver/classes/range.js:133:47
38 verbose stack at Array.map (<anonymous>)
38 verbose stack at Range.parseRange (/Users/gthb/.nvm/versions/node/v16.18.0/lib/node_modules/npm/node_modules/semver/classes/range.js:133:35)
38 verbose stack at /Users/gthb/.nvm/versions/node/v16.18.0/lib/node_modules/npm/node_modules/semver/classes/range.js:34:22
38 verbose stack at Array.map (<anonymous>)
38 verbose stack at new Range (/Users/gthb/.nvm/versions/node/v16.18.0/lib/node_modules/npm/node_modules/semver/classes/range.js:34:8)
38 verbose stack at Object.intersects (/Users/gthb/.nvm/versions/node/v16.18.0/lib/node_modules/npm/node_modules/semver/ranges/intersects.js:3:8)
38 verbose stack at OverrideSet.getEdgeRule (/Users/gthb/.nvm/versions/node/v16.18.0/lib/node_modules/npm/node_modules/@npmcli/arborist/lib/override-set.js:53:18)
39 verbose cwd /Users/gthb/git/GRID-client
40 verbose Darwin 22.1.0
41 verbose node v16.18.0
42 verbose npm v9.2.0
43 error Invalid comparator: @grid-is/pgsql-ast-parser@^111.0.0
Expected Behavior
I expect npm install to succeed with NPM 9 like it does with NPM 8 (or else output a more informative error message, if there is something wrong with the package override that NPM 8 was not revealing).
Steps To Reproduce
I would extract minimal steps to reproduce this, except, I put in that work in https://github.com/npm/cli/issues/5007 and that's been totally ignored for half year. I'll happily put in the work here if there's a hint that someone cares for it. :)
Environment
- npm: 9.2.0
- Node.js: 16.18.0
- OS Name: Darwin 22.1.0
- System Model Name: Macbook Pro
- npm config:
; "user" config from /Users/gthb/.npmrc
@grid-is:registry = "https://registry.npmjs.org/"
//registry.npmjs.org/:_authToken = (protected)
; "project" config from /Users/gthb/git/GRID-client/.npmrc
engine-strict = true
; "cli" config from command line options
location = "project"
; node bin location = /Users/gthb/.nvm/versions/node/v16.18.0/bin/node
; node version = v16.18.0
; npm local prefix = /Users/gthb/git/GRID-client
; npm version = 9.2.0
; cwd = /Users/gthb/git/GRID-client
; HOME = /Users/gthb
; 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 scoped override failure with npm 9.2.0, then inspect @npmcli/arborist/lib/override-set.js and the semver Comparator/Range stack shown in the report. Done means npm install succeeds for the override as it does in npm 8, or reports a more informative validation error; no repository test is named in the issue.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript, nodejs
- Domain
- cli, devtools
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100