npm / cli

the package manager for JavaScript
https://docs.npmjs.com/cli/
Other
8.4k stars 3.12k forks source link

[BUG] ENOVERSIONS for undefined when using github dependency #6577

Open alt-jero opened 1 year ago

alt-jero commented 1 year ago

Is there an existing issue for this?

This issue exists in the latest npm version

Current Behavior

Package name reads 'undefined' in ENOVERSIONS error when dependency is a git(hub) package.

$ npm i -D alt-jero/my-private-package#semver:~0.0.2
npm ERR! code ENOVERSIONS
npm ERR! No versions available for undefined

npm ERR! A complete log of this run can be found in: /Users/jero/.npm/_logs/2023-06-20T23_27_09_712Z-debug-0.log

Probably the 'undefined' is referring to the name field of the package.json, which hasn't been fetched because the requested version tag was not found.

Expected Behavior

'Method' references "Steps to Reproduce".

For method 1: Use the URL specified in the command (without the semver hash)

npm ERR! code ENOVERSIONS
npm ERR! No versions available for <your github username>/the-dependency

For method 2: Use the name specified in package.json of the host

npm ERR! code ENOVERSIONS
npm ERR! No versions available for the-dependency

Also, a short explanatory text might go a long way:

npm INFO: Versions must be defined as git tags
npm INFO: If you can push to the repository, ensure you have also pushed the tags
npm INFO: If you cannot alter the repository, omit the semver specifier

Steps To Reproduce

Setup:

  1. The Dependency – Create a github repo containing a package.json with version 1.0.0 but no git version tags.
  2. The Host – Create a local directory and npm init it.
  3. Proceed

Method 1: CLI

  1. run npm i <your github username>/the-dependency#semver:~1.0.0
  2. Wait...
  3. Observe the error

Method 2: package.json

  1. Add "your-test-package": "<your github username>/the-dependency#semver:~1.0.0" to the package.json of the host
  2. run npm i
  3. Wait, and observe the error

Environment

//registry.npmjs.org/:_authToken = (protected)

; node bin location = /usr/local/bin/node ; node version = v18.8.0 ; npm local prefix = /Users/jero/dev ; npm version = 9.7.1 ; cwd = /Users/jero/dev ; HOME = /Users/jero ; Run npm config ls -l to show all defaults.

milaninfy commented 4 months ago

@alt-jero I am not able to reproduce this with given steps for public packages like lodash or underscore, I think this is because I am using correct version, but I see the pacakge name is undefined when I am using range outside of correct range.

~/workarea/rep $ npm install jashkenas/underscore#semver:^1.13.1

added 1 package, and audited 2 packages in 9s

found 0 vulnerabilities

~/workarea/rep $ npm -v
9.7.1

~/workarea/rep $ npm ls
rep@1.0.0 /Users/milaninfy/workarea/rep
└── underscore@1.13.6 (git+ssh://git@github.com/jashkenas/underscore.git#bd2d35c87620a7da36250a006c97fdae89f4902d)

~/workarea/rep $ npm install lodash/lodash                      

added 1 package, and audited 3 packages in 18s

found 0 vulnerabilities

~/workarea/rep $ npm ls
rep@1.0.0 /Users/milaninfy/workarea/rep
├── lodash@5.0.0 (git+ssh://git@github.com/lodash/lodash.git#a67a085cc0612f5b83d78024e507427dab25ca2c)
└── underscore@1.13.6 (git+ssh://git@github.com/jashkenas/underscore.git#bd2d35c87620a7da36250a006c97fdae89f4902d)
alt-jero commented 4 months ago

Hi Milaninfy!

Thanks for getting back to me!

I think.... If it's working for you with public packages, it may be that something about my specific packages is not correct or at least not setup the way NPM expects.

I can't do it just now, but I will try with the same package you mentioned to see if that one works for me as intended.

If so, then I'll know it's my repo with the issue and not NPM.

If not, I'll need to gather some more info and perhaps create a runnable example somehow.

Also I have a new laptop with a different OS version (and possibly a different NPM version at this point), so I'll try the tests on that one too.

milaninfy commented 3 months ago

error message shows undefined for package name if the version does not exist. Reproducible on 10.8.1

~/workarea/rep $ npm install jashkenas/underscore#semver:^11.13.1
npm error code ETARGET
npm error notarget No matching version found for undefined@^11.13.1.
npm error notarget In most cases you or one of your dependencies are requesting
npm error notarget a package version that doesn't exist.