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 does not respect version range if a compatible version is found inside any package installed globally #7486

Closed
2 tasks done
mshima opened this issue May 8, 2024 · 7 comments · Fixed by #7587
Closed
2 tasks done
Assignees
Labels
Bug thing that needs fixing Priority 2 secondary priority issue

Comments

@mshima
Copy link

mshima commented May 8, 2024

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

Installed package is used even if the version range does not match.

npm install -g generator-jhipster@8.3.0 generator-jhipster-native@2.1.0
npx generator-jhipster@8.4.0 --version
8.3.0

Expected Behavior

The version range should be respected.

npm install -g generator-jhipster@8.3.0
npx generator-jhipster@8.4.0 --version
8.4.0

Steps To Reproduce

No response

Environment

  • npm: 10.7.0
  • Node.js: v18.20.2
  • OS Name: MacOS
  • System Model Name: MacBook Air
  • npm config:
; "builtin" config from /opt/homebrew/lib/node_modules/npm/npmrc

prefix = "/opt/homebrew"

; "user" config from /Users/mshima/.npmrc

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

; node bin location = /usr/local/bin/node
; node version = v18.20.2
; npm local prefix = /Users/mshima/git/test
; npm version = 10.7.0
; cwd = /Users/mshima/git/test
; HOME = /Users/mshima
; Run `npm config ls -l` to show all defaults.
@milaninfy
Copy link
Contributor

For me it's showing correct version

~ $ npx generator-jhipster@8.4.0 --version
8.4.0
~ $ npm ls -g 
/Users/testing/.nvm/versions/node/v22.0.0/lib
├── corepack@0.26.0
├── generator-jhipster@8.3.0
├── latest@0.2.0
└── npm@10.7.0

@mshima
Copy link
Author

mshima commented May 8, 2024

% npx -v
10.7.0
% npx generator-jhipster@8.4.0 --version
8.3.0
% npm ls -g
/opt/homebrew/lib
.
├── generator-jhipster@8.3.0
.

Anything else I could do to debug?

@mshima mshima changed the title [BUG] npx does not respect version range if package is found locally or globally [BUG] npx does not respect version range if package is found globally May 8, 2024
@milaninfy
Copy link
Contributor

does you cwd has that package installed ?
what does npm ls shows from where you are running the command ?

@mshima
Copy link
Author

mshima commented May 8, 2024

does you cwd has that package installed ? what does npm ls shows from where you are running the command ?

It's an empty folder.

% npm ls
/Users/mshima/git/test
└── (empty)

@mshima
Copy link
Author

mshima commented May 8, 2024

@milaninfy I think a found a way to reproduce:

npm install -g generator-jhipster@8.3.0 generator-jhipster-native@latest
% npx generator-jhipster@8.4.0 --version
8.3.0

If I remove every global package and install the generator-jhipster, it works.
Then if I install generator-jhipster-native that have generator-jhipster@8.4.0 as a dependency, the problem is reproducible.

@mshima
Copy link
Author

mshima commented May 8, 2024

I've added a console.log in /usr/local/lib/node_modules/npm/node_modules/libnpmexec/lib/index.js:

      // package requested by specific version
      if (spec.type === 'version' && (node.pkgid === spec.raw)) {
        console.log(node)
        return { node }

It prints:

% npx generator-jhipster@8.4.0 --version
⠦ArboristNode {
  name: 'generator-jhipster',
  version: '8.4.0',
  location: 'node_modules/generator-jhipster-native/node_modules/generator-jhipster',
  path: '/usr/local/lib/node_modules/generator-jhipster-native/node_modules/generator-jhipster',
.
.
.
8.3.0

generator-jhipster inside generator-jhipster-native is found. But the root (8.3.0) is used.

@mshima mshima changed the title [BUG] npx does not respect version range if package is found globally [BUG] npx does not respect version range if a compatible version is found inside any package installed globally May 8, 2024
@wraithgar
Copy link
Member

Duplicated in a workspace off of latest

@wraithgar ➜ /workspaces/cli (latest) $ npx generator-jhipster@8.4.0 --version
8.3.0
@wraithgar ➜ /workspaces/cli (latest) $ npm ls -g
/usr/local/share/nvm/versions/node/v20.12.1/lib
├── corepack@0.25.2
├── generator-jhipster-native@2.1.0
├── generator-jhipster@8.3.0
├── npm@10.5.0
└── pnpm@8.15.6

@wraithgar wraithgar added Priority 2 secondary priority issue and removed Needs Triage needs review for next steps labels May 10, 2024
@milaninfy milaninfy self-assigned this May 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug thing that needs fixing Priority 2 secondary priority issue
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants