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] updating to version 11 doesn't work correctly #8000

Open
2 tasks done
rakleed opened this issue Dec 25, 2024 · 9 comments
Open
2 tasks done

[BUG] updating to version 11 doesn't work correctly #8000

rakleed opened this issue Dec 25, 2024 · 9 comments
Labels
Bug thing that needs fixing Needs Triage needs review for next steps

Comments

@rakleed
Copy link

rakleed commented Dec 25, 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

I see 10.9.0.

And I have seen already twice in console the warning to update to npm@11.

But when I run npm list -g, I see:

/opt/homebrew/lib
└── [email protected]

Expected Behavior

I should see 11.0.0.

Steps To Reproduce

  1. I have installed [email protected] with [email protected].
npm install -g [email protected]
npm -v

Environment

  • npm: 10.9.0
  • Node.js: v22.12.0
  • OS Name: macOS 15.2
  • System Model Name: MacBook
  • npm config:
; "builtin" config from /opt/homebrew/Cellar/node@22/22.12.0/lib/node_modules/npm/npmrc

prefix = "/opt/homebrew"

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

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

; node bin location = /opt/homebrew/Cellar/node@22/22.12.0/bin/node
; node version = v22.12.0
; npm local prefix = /Users/rakleed
; npm version = 10.9.0
; cwd = /Users/rakleed
; HOME = /Users/rakleed
; Run `npm config ls -l` to show all defaults.
@rakleed rakleed added Bug thing that needs fixing Needs Triage needs review for next steps labels Dec 25, 2024
@ljharb
Copy link
Contributor

ljharb commented Dec 25, 2024

It seems like you used homebrew to install npm separately (npm should never be installed separately from node). If you brew uninstall it, you should find you have the version you expect already?

@rakleed
Copy link
Author

rakleed commented Dec 25, 2024

I've never installed npm through Homebrew myself, and when calling brew list I didn't find it in the list of installed ones.

Now I removed node and reinstall it (brew uninstall node@22 && brew install node@22), but nothing changed - the npm version is still 10.9.0 even after the update via npm install npm@11 -g.

@ljharb
Copy link
Contributor

ljharb commented Dec 26, 2024

I’d suggest installing node through an official means, which means, not homebrew at all. nvm or another version manager that installs from nodejs.org is your best bet.

@OS-Scratch
Copy link

I had a notification when running npm to update it using npm install npm@latest and it worked flawlessly there for me on Windows.

@ljharb
Copy link
Contributor

ljharb commented Dec 28, 2024

@OS-Scratch if you didn't include -g, then it just installed it locally in your project, which won't do what you want it to.

@OS-Scratch
Copy link

I'm using Windows, and even without -g, it installed it globally. But installing it locally would be helpful to try out if it works, and if it works, then apply it globally.

@ljharb
Copy link
Contributor

ljharb commented Dec 28, 2024

If it installed it globally without -g then i'd file another issue; that seems bad.

@OS-Scratch
Copy link

Sorry!

@shadowspawn
Copy link
Contributor

shadowspawn commented Jan 1, 2025

Short version: what does running these show?

where npm
echo $PATH 

Long version

First, what went wrong. I suspect your problem is due to Homebrew node@22 being keg-only and requires some manual setup. I noticed this warning when I tried running brew install node@22.

==> Caveats
==> node@22
node@22 is keg-only, which means it was not symlinked into /opt/homebrew,
because this is an alternate version of another formula.

If you need to have node@22 first in your PATH, run:
  echo 'export PATH="/opt/homebrew/opt/node@22/bin:$PATH"' >> ~/.zshrc

Assuming you followed those instructions, I reproduced the problem you described:

$ brew install node@22
$ export PATH="/opt/homebrew/opt/node@22/bin:$PATH"
$ npm --version
10.9.0
$ npm install --global npm
$ npm --version
10.9.0
$ npm ls --global
/opt/homebrew/lib
├── [email protected]
$ where npm                                               
/opt/homebrew/opt/node@22/bin/npm
/opt/homebrew/bin/npm

I now have two versions of npm installed, and the location of the older one is explicitly first in the PATH.

I am not sure of the most elegant way to solve this if you want to keep using brew for managing node, but it isn't an npm problem as such.

(Speculation after a few searches. Installing old versions using brew seems to be a bit complicated, and the LTS version of node is an "old" version. A simple thing to try in the medium term would be to put node@22 last instead of first in your PATH, but will require manual maintenance in the future. Start a new shell after making the changes to make sure you aren't getting a cached location for npm.)

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
Projects
None yet
Development

No branches or pull requests

4 participants