jorgebucaran / nvm.fish

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

NVM not starting with the version set in nvm_default_version #162

Closed Rush closed 3 years ago

Rush commented 3 years ago

My $nvm_default_version is set to v14.17.5 but NVM is starting with an older version. Please see the following log for details. It's driving me crazy so I would appreciate any help.

rush@rushbox: ~/.c/fish » node --version
v14.15.0
rush@rushbox: ~/.c/fish » nvm -v
nvm, version 2.2.5
rush@rushbox: ~/.c/fish » nvm current
v14.17.3
rush@rushbox: ~/.c/fish » which node
/home/rush/.config/nvm/14.15.0/bin/node
rush@rushbox: ~/.c/fish » node --version
v14.15.0
rush@rushbox: ~/.c/fish » nvm use 14
Now using Node v14.17.5 (npm 6.14.14) ~/.local/share/nvm/v14.17.5/bin/node
rush@rushbox: ~/.c/fish 24ms » node --version
v14.17.5
rush@rushbox: ~/.c/fish » which node
/home/rush/.local/share/nvm/v14.17.5/bin/node
rush@rushbox: ~/.c/fish » fish --version
fish, version 3.3.1
rush@rushbox: ~/.c/fish » cat ~/.config/fish/config.fish|grep nvm
set --universal nvm_default_version v14.17.5
rush@rushbox: ~/.c/fish » echo $nvm_default_version
v14.17.5
jorgebucaran commented 3 years ago

Can't reproduce. Works as expected here.

You shouldn't set universal variables in your config.fish, they are meant to be set interactively.

jorgebucaran commented 3 years ago

Do you happen to be using both nvm-sh/nvm and nvm.fish? You shouldn't do that. Use one or the other.

Rush commented 3 years ago

Do you happen to be using both nvm-sh/nvm and nvm.fish? You shouldn't do that. Use one or the other.

No I am not using nvm-sh/nvm. I am still having this problem. Any tips on how I can debug what's happening? In what place in the code is nvm.fish actually activating the current node version?

Seems like what I need to happen is execute "nvm use 14" on every new shell instance.

jorgebucaran commented 3 years ago

... activating the current node version

You probably mean nvm_default_version. That happens on every new shell here:

https://github.com/jorgebucaran/nvm.fish/blob/8922519b432140e6eaafbb4dc397505c8da80139/conf.d/nvm.fish#L26-L28

Rush commented 3 years ago

Thanks! It seems something it setting nvm_current_version global to a wrong value prior to this code running ! set --query nvm_current_version. I have grepped through my ~/.config/fish to no avail.

Changing to always nvm use regardless of nvm_current_version fixes it but I'm yet to solve the actual mystery

 status is-interactive && 
     set --query nvm_default_version && 
     nvm use $nvm_default_version >/dev/null 
jorgebucaran commented 3 years ago

You should set nvm_default_version if you want to persist Node across sessions, not nvm_current_version. If you are not setting nvm_current_version, then it could be a bug in nvm.