So about a year ago, I started getting this strange npm issue, where the terminal was detecting v17.9.1, eventhough I was using a later version. This started causing npm i, npm run dev, etc to stop working as I would be prompted to upgrade my node version.
I asked alot of my buddies, scoured stackoverflow and reddit, asked gpt and claude, but it seemed the issue was kind of unheard of to an extent. I went as far as ground up reinstalling npm, nvm, and node. Still, no luck. Nvm didnt even see any v17 installed. I kind of left it at that.
Well a week ago I wanted to make a new project, and the issue came up again. This time I had my Guji, Ethiopian light roast from DAK roasters, brewed using a v60, and that was enough to give me the motivation to solve it. So I started digging myself and looked through documentation like a nerd.
The premise of the issue was something like this (this is a recent example)
$ nvm use
Now using node v22.12.0 (npm v10.9.0)
$ npm run dev
> dev
> react-router dev
️⚠️ Oops, Node v17.9.1 detected. react-router requires a Node version greater than 20.
The gist of it is:
When you run something like npm run dev, npm modifies the PATH by prepending node_modules/.bin directories
The search order goes:
/Users/*/node_modules/.bin/
/Users/*/Documents/node_modules/.bin/
/Users/*/Documents/GitHub/node_modules/.bin/
[...your project's node_modules...]
[...then your normal PATH with nvm...]
The issue with me, is a rouge npm package called "node" (v17.9.1) randomly ended up in the home directory:
/Users/*/node_modules/node/bin. So when npm executes node, it would pick up the version through that first.
So why did npm --version not pick this up? That's because no npm PATH manipulation had occurred yet, and the shell used the normal PATH where nvm's Node comes first. And saw v22.12.0 as expected.
The fix: Just delete the random node module and it should be good to go. I don't even know how it ended up there if I'm completely honest, maybe I was tired after a long day of capstone grinding.
TLDR: don't be dumb like me and accidentally install node into your home directory and forget about it...there will be reprecusions. If you do, just fix it lol.
Top comments (0)