Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] npx doesn’t consider globally installed namespaced packages #7257

Closed
2 tasks done
rauschma opened this issue Feb 28, 2024 · 7 comments
Closed
2 tasks done

[BUG] npx doesn’t consider globally installed namespaced packages #7257

rauschma opened this issue Feb 28, 2024 · 7 comments
Labels
Bug thing that needs fixing Needs Triage needs review for next steps Release 10.x

Comments

@rauschma
Copy link

rauschma commented Feb 28, 2024

Is there an existing issue for this?

  • I have searched the existing issues

Related issues

This issue exists in the latest npm version

  • I am using the latest npm

Current Behavior

Installation

I installed a package via sudo npm link (without publishing it to the registry):

% cd ~/tmp/hello/
% sudo npm link

Result:

% npm ls -g
/usr/local/lib
├── @rauschma/hello@1.0.0 -> ./../../../Users/rauschma/tmp/hello
├── corepack@0.24.0
├── npm@10.2.4
└── typescript@5.3.3

Interaction

I’m unable to use npx @rauschma/hello:

% cd $HOME

% hello
Hello!

% npx hello
Hello!

% npx @rauschma/hello
npm ERR! code E404
npm ERR! 404 Not Found - GET https://registry.npmjs.org/@rauschma%2fhello - Not found
npm ERR! 404 
npm ERR! 404  '@rauschma/hello@*' is not in this registry.
npm ERR! 404 
npm ERR! 404 Note that you can also install from a
npm ERR! 404 tarball, folder, http url, or git url.

% npx --package @rauschma/hello hello   
npm ERR! code E404
npm ERR! 404 Not Found - GET https://registry.npmjs.org/@rauschma%2fhello - Not found
npm ERR! 404 
npm ERR! 404  '@rauschma/hello@*' is not in this registry.
npm ERR! 404 
npm ERR! 404 Note that you can also install from a
npm ERR! 404 tarball, folder, http url, or git url.

Expected Behavior

I expected npx @rauschma/hello to work.

Steps To Reproduce

Environment

  • npm: 10.2.4
  • Node.js: v21.6.2
  • OS Name: macOS Sonoma 14.3.1
  • System Model Name: MacBook Pro 14-inch with an M1 Pro
  • npm config:
; "user" config from /Users/rauschma/.npmrc

//registry.npmjs.org/:_authToken = (protected) 
loglevel = "error" 

; node bin location = /usr/local/bin/node
; node version = v21.6.2
; npm local prefix = /Users/rauschma/tmp/hello
; npm version = 10.2.4
; cwd = /Users/rauschma/tmp/hello
; HOME = /Users/rauschma
; Run `npm config ls -l` to show all defaults.
@rauschma rauschma added Bug thing that needs fixing Needs Triage needs review for next steps Release 10.x labels Feb 28, 2024
@ljharb
Copy link
Contributor

ljharb commented Feb 28, 2024

If you’re linking it globally you don’t need npx to use it, tho.

@rauschma
Copy link
Author

I know! The idea is to invoke a bin script via npx then users can choose between:

  • Installing locally
  • Installing globally
  • Letting npx install it

@ljharb
Copy link
Contributor

ljharb commented Feb 28, 2024

yeah that makes sense - i would definitely expect npx to check local first, then global, then the registry. Is this perhaps a duplicate of #5596?

@rauschma
Copy link
Author

i would definitely expect npx to check local first, then global, then the registry.

Right. That’s how it works with non-namespaced packages.

@what1s1ove
Copy link

what1s1ove commented Mar 5, 2024

Hey @ljharb !

I have the same problem, and it seems it started with the 20.11 Node release (and its other components).

Node.js - 20.10.0
npm/npx - 10.2.3
build command - pass
image

Node.js - 20.11.0
npm/npx - 10.2.4
build command - fail (due to the suggestion to install the package. What I really don’t want, but I want to use the version from node_modules (behavior of Node 20.10)
image

I do not have a lot of time to investigate more now, but hope it will help a bit 🙏

@milaninfy
Copy link
Contributor

not able to reproduce the issue with the steps provided. Likely that this issue might be fixed. Please try with latest npm.

~/workarea/rep $ sudo npm link

added 1 package, and audited 3 packages in 453ms

found 0 vulnerabilities
~/workarea/rep $ hello
Hello dfsdf!
~/workarea/rep $ npx hello
Hello dfsdf!
~/workarea/rep $ npx @rauschma/hello
Hello dfsdf!
~/workarea/rep $ npm -v
10.2.4

@rauschma
Copy link
Author

rauschma commented Apr 29, 2024

Thanks! It indeed looks like the issue is fixed now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug thing that needs fixing Needs Triage needs review for next steps Release 10.x
Projects
None yet
Development

No branches or pull requests

4 participants