jorgebucaran / nvm.fish

The Node.js version manager you'll adore, crafted just for Fish
https://git.io/nvm.fish
MIT License
2.06k stars 69 forks source link

`nvm use` seems to use the wrong version no matter what #177

Closed ian-h-chamberlain closed 2 years ago

ian-h-chamberlain commented 2 years ago

Hi, I seem to be having trouble getting nvm to use the version that I specify in .nvmrc, or at all:

$ command cat .nvmrc
16.13.0

$ nvm current 
v16.13.0

$ nvm use 
Now using Node v17.4.0 (npm 8.3.1) /usr/local/Cellar/node/17.4.0/bin/node

$ nvm use v16.13.0
Now using Node v17.4.0 (npm 8.3.1) /usr/local/Cellar/node/17.4.0/bin/node

$ nvm use 16.13.0
Now using Node v17.4.0 (npm 8.3.1) /usr/local/Cellar/node/17.4.0/bin/node

I updated nvm to check that it's latest:

$ nvm --version 
nvm, version 2.2.7

Are there any logs or similar I can look at to figure out what's going on here? I saw #176 but it seems like that's fixed, and slightly different symptoms anyway.

Please let me know if there's anything I can do to help debug. Thanks!

jorgebucaran commented 2 years ago

Can you check if your local ~/.local/share/nvm/.index file lists all Node versions?

$ cat ~/.local/share/nvm/.index
v17.7.2 latest
v17.7.1
v17.7.0
v17.6.0
v17.5.0
v17.4.0
v17.3.1
v17.3.0
v17.2.0
v17.1.0
v17.0.1
v17.0.0
v16.14.2 lts/gallium

...
ian-h-chamberlain commented 2 years ago

It has the relevant versions and many more:

$ command cat ~/.local/share/nvm/.index
v17.7.2 latest
v17.7.1
v17.7.0
v17.6.0
v17.5.0
v17.4.0
v17.3.1
v17.3.0
v17.2.0
v17.1.0
v17.0.1
v17.0.0
v16.14.2 lts/gallium
v16.14.1 lts/gallium
v16.14.0 lts/gallium
v16.13.2 lts/gallium
v16.13.1 lts/gallium
v16.13.0 lts/gallium
v16.12.0
v16.11.1
v16.11.0
v16.10.0
v16.9.1
v16.9.0
...
jorgebucaran commented 2 years ago

You also appear to have installed Node using Homebrew in the first place, yes? Not an issue, but how come nvm current showed 16.13.0 above? What did you do to switch to that version in the first place?

Also, check these for me, please:

$ nvm ls
$ la ~/.local/share/nvm/
ian-h-chamberlain commented 2 years ago

Yes, it looks like I have version 17.4.0 installed via brew, which I guess is being used in the cases where the local .nvmrc version is not being used.

Here's the output you asked for:

$ nvm ls 
     system  
   v10.14.2 lts/dubnium 
    v13.7.0  
 ▶ v16.13.0 lts/gallium 
    v17.7.2 latest 

$ la ~/.local/share/nvm/
total 16
drwxrwxr-x   7 ichamberlain  staff   224B Mar 18 10:49 ./
drwx------  10 ichamberlain  staff   320B Oct 28 10:34 ../
-rw-rw-r--   1 ichamberlain  staff   5.7K Mar 18 10:49 .index
drwxrwxr-x   9 ichamberlain  staff   288B Mar 11  2021 v10.14.2/
drwxrwxr-x   9 ichamberlain  staff   288B Feb 10  2021 v13.7.0/
drwxrwxr-x   9 ichamberlain  staff   288B Mar 18 10:37 v16.13.0/
drwxrwxr-x   9 ichamberlain  staff   288B Mar 18 10:35 v17.7.2/

Interestingly, I opened a new terminal and nvm use seems to work correctly there:

$ nvm use 
Now using Node v16.13.0 (npm 8.1.0) ~/.local/share/nvm/v16.13.0/bin/node

$ node --version
v16.13.0

Even stranger, this appears to have changed after running nvm use once in the "old" (bad) session!

$ nvm use 
Now using Node v16.13.0 (npm 8.1.0) ~/.local/share/nvm/v16.13.0/bin/node

$ node --version
v16.13.0

$ nvm use 
Now using Node v17.4.0 (npm 8.3.1) /usr/local/Cellar/node/17.4.0/bin/node

how come nvm current showed 16.13.0 above? What did you do to switch to that version in the first place?

That is kind of the core of the issue – the nvm current and nvm use were out of sync with each other. I can still reproduce this in the terminal session I have open (this is two commands immediately run one after another):

$ nvm use 
Now using Node v17.4.0 (npm 8.3.1) /usr/local/Cellar/node/17.4.0/bin/node

$ nvm current 
v16.13.0

One final note: in cases where the correct version is use, I can see that PATH has the expected value prepended:

$ set -S PATH 
$PATH: set in global scope, exported, a path variable with 23 elements
$PATH[1]: |/Users/ichamberlain/.local/share/nvm/v16.13.0/bin|

For cases where the wrong version is there, no such PATH entry exists. I assume this is related to the reason nvm reports the system (homebrew) version.

jorgebucaran commented 2 years ago

Thank you for all the info, very helpful. Maybe I introduced a bug while fixing #176. I'll look into it.

Are you able to reproduce this issue in a new terminal after uninstalling and reinstalling nvm.fish?

ian-h-chamberlain commented 2 years ago

Are you able to reproduce this issue in a new terminal after uninstalling and reinstalling nvm.fish?

Yep, reinstalling (and reinstalling the appropriate node version) seems to have done the trick. Thanks for the workaround!

jorgebucaran commented 2 years ago

If I understand correctly, it seems that uninstalling and reinstalling nvm.fish fixed the issue and now you can't reproduce it.

ian-h-chamberlain commented 2 years ago

That's correct, I haven't been able to reproduce it after reinstalling nvm.fish.

franciscolourenco commented 2 years ago

I just experienced the same issue. Reinstalling fixed the issue.

franciscolourenco commented 2 years ago

Upgrading was not sufficient.