Skip to content

nvm use fails even after installing the version #226

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

Closed
NV4RE opened this issue Sep 3, 2024 · 12 comments
Closed

nvm use fails even after installing the version #226

NV4RE opened this issue Sep 3, 2024 · 12 comments

Comments

@NV4RE
Copy link
Contributor

NV4RE commented Sep 3, 2024

Description

I am experiencing an issue with nvm.fish where I am unable to use a Node version even after installing it. Here are the steps I followed:

  1. Installed the latest version of Node using nvm install latest.
  2. Attempted to use the installed version with nvm use v22.7.0, but received the error message "nvm: Can't use Node 'v22.7.0', version must be installed first".
  3. Tried using nvm use v22 and nvm use 22, but received the same error message.
  4. Verified that the version is installed by checking the ~/.local/share/nvm/ directory.
nv4re@Mac-mini ~/D/S/s/some-project (main)> node -v
fish: Unknown command: node
nv4re@Mac-mini ~/D/S/s/some-project (main) [127]> nvm install latest
Installing Node v22.7.0 latest
Fetching https://nodejs.org/dist/v22.7.0/node-v22.7.0-darwin-arm64.tar.gz
Now using Node v22.7.0 (npm 10.8.2) ~/.local/share/nvm/v22.7.0/bin/node
nv4re@Mac-mini ~/D/S/s/some-project (main)> nvm use v22.7.0
nvm: Can't use Node "v22.7.0", version must be installed first
nv4re@Mac-mini ~/D/S/s/some-project (main) [1]> nvm use v22
nvm: Can't use Node "v22", version must be installed first
nv4re@Mac-mini ~/D/S/s/some-project (main) [1]> nvm install v22
Now using Node v22.7.0 (npm 10.8.2) ~/.local/share/nvm/v22.7.0/bin/node
nv4re@Mac-mini ~/D/S/s/some-project (main)> nvm use v22
nvm: Can't use Node "v22", version must be installed first
nv4re@Mac-mini ~/D/S/s/some-project (main) [1]> nvm install 22
Now using Node v22.7.0 (npm 10.8.2) ~/.local/share/nvm/v22.7.0/bin/node
nv4re@Mac-mini ~/D/S/s/some-project (main)> nvm use 22
nvm: Can't use Node "22", version must be installed first
nv4re@Mac-mini ~/D/S/s/some-project (main) [1]> nvm use v22
nvm: Can't use Node "v22", version must be installed first
nv4re@Mac-mini ~/D/S/s/some-project (main) [1]> ls -la  ~/.local/share/nvm/
total 16
drwxr-xr-x  4 nv4re  staff   128 Sep  3 14:28 ./
drwx------  4 nv4re  staff   128 Sep  3 14:27 ../
-rw-r--r--  1 nv4re  staff  7496 Sep  3 14:28 .index
drwxr-xr-x  9 nv4re  staff   288 Sep  3 14:28 v22.7.0/

Expected Behavior

After installing a Node version using nvm install, I should be able to use it with nvm use.

Actual Behavior

Even after installing the version, I receive an error message stating that the version must be installed first.

Environment

  • Operating System: macOS
  • Shell: Fish
  • nvm.fish version: latest

Steps to Reproduce

  1. Install the latest version of Node using nvm install latest.
  2. Attempt to use the installed version with nvm use v22.7.0.
  3. Verify that the version is installed by checking the ~/.local/share/nvm/ directory.

Additional Information

I have attached the output of the ls -la ~/.local/share/nvm/ command, which shows that the version is indeed installed.

total 16
drwxr-xr-x  4 nv4re  staff   128 Sep  3 14:28 ./
drwx------  4 nv4re  staff   128 Sep  3 14:27 ../
-rw-r--r--  1 nv4re  staff  7496 Sep  3 14:28 .index
drwxr-xr-x  9 nv4re  staff   288 Sep  3 14:28 v22.7.0/

Noted that nvm list give empty result

I would appreciate any help in resolving this issue. Thank you

@jorgebucaran
Copy link
Owner

Are you using the latest Fish as well? How did you install nvm.fish?

@NV4RE
Copy link
Contributor Author

NV4RE commented Sep 4, 2024

I'm currently using Fish shell version 3.7.1

I installed using fisher install jorgebucaran/nvm.fish. Despite multiple attempts to install and remove it, as well as cleaning the ~/.local/share/nvm/ directory, I'm still experiencing issues.

@jorgebucaran
Copy link
Owner

What is the actual Node version after installing v22 with nvm? Can you try installing other versions (just to check)? Do you also happen to have a system Node installation, and if so, how did you install it?

@NV4RE
Copy link
Contributor Author

NV4RE commented Sep 4, 2024

I do not have a system Node installation, as I previously used brew:nvm before switching to fish shell and uninstalling brew:nvm.

Last login: Wed Sep  4 15:31:47 on ttys000
Welcome to fish, the friendly interactive shell
Type help for instructions on how to use fish
nv4re@Mac-mini ~> nvm install v20
Installing Node v20.17.0 lts/iron
Fetching https://nodejs.org/dist/v20.17.0/node-v20.17.0-darwin-arm64.tar.gz
Now using Node v20.17.0 (npm 10.8.2) ~/.local/share/nvm/v20.17.0/bin/node
nv4re@Mac-mini ~> nvm use v20
nvm: Can't use Node "v20", version must be installed first
nv4re@Mac-mini ~ [1]> nvm install v16
Installing Node v16.20.2 lts/gallium
Fetching https://nodejs.org/dist/v16.20.2/node-v16.20.2-darwin-arm64.tar.gz
Now using Node v16.20.2 (npm 8.19.4) ~/.local/share/nvm/v16.20.2/bin/node
nv4re@Mac-mini ~> nvm use v16
nvm: Can't use Node "v16", version must be installed first
nv4re@Mac-mini ~ [1]> nvm list
nv4re@Mac-mini ~ [1]> ls -la  ~/.local/share/nvm/
total 16
drwxr-xr-x  6 nv4re  staff   192 Sep  4 15:32 ./
drwx------  4 nv4re  staff   128 Sep  3 14:27 ../
-rw-r--r--  1 nv4re  staff  7504 Sep  4 15:32 .index
drwxr-xr-x  9 nv4re  staff   288 Sep  4 15:32 v16.20.2/
drwxr-xr-x  9 nv4re  staff   288 Sep  4 15:32 v20.17.0/
drwxr-xr-x  9 nv4re  staff   288 Sep  3 14:28 v22.7.0/
brew uninstall nvm
Error: No such keg: /opt/homebrew/Cellar/nvm

@jorgebucaran
Copy link
Owner

Can you make sure that you're running the latest nvm.fish? If you are, see if the code matches what's in this repo jorgebucaran/nvm.fish/tree/main/functions/*. This issue is really odd, and I have no idea what's causing it. I couldn't reproduce the problem on my end either.

Also, let's take a look at your config.fish or any custom conf.d/ snippets you have. And what plugins are you using?

@NV4RE
Copy link
Contributor Author

NV4RE commented Sep 4, 2024

config.fish

if status is-interactive
    # Commands to run in interactive sessions can go here
end

fzf --fish | source

I have compare main branch of the nvm.fish repository on GitHub with my local ~/.config/fish directory and found them to be identical.

Only in /Users/nv4re/Documents/Personal/nv4re/nvm.fish: .git
Only in /Users/nv4re/Documents/Personal/nv4re/nvm.fish: .github
Only in /Users/nv4re/Documents/Personal/nv4re/nvm.fish: LICENSE.md
Only in /Users/nv4re/Documents/Personal/nv4re/nvm.fish: README.md
Only in /Users/nv4re/.config/fish/completions: fisher.fish
Only in /Users/nv4re/.config/fish/completions: fzf_configure_bindings.fish
Only in /Users/nv4re/.config/fish/conf.d: fzf.fish
Only in /Users/nv4re/.config/fish: config.fish
Only in /Users/nv4re/.config/fish: fish_plugins
Only in /Users/nv4re/.config/fish: fish_variables
Only in /Users/nv4re/.config/fish/functions: _fzf_configure_bindings_help.fish
Only in /Users/nv4re/.config/fish/functions: _fzf_extract_var_info.fish
Only in /Users/nv4re/.config/fish/functions: _fzf_preview_changed_file.fish
Only in /Users/nv4re/.config/fish/functions: _fzf_preview_file.fish
Only in /Users/nv4re/.config/fish/functions: _fzf_report_diff_type.fish
Only in /Users/nv4re/.config/fish/functions: _fzf_report_file_type.fish
Only in /Users/nv4re/.config/fish/functions: _fzf_search_directory.fish
Only in /Users/nv4re/.config/fish/functions: _fzf_search_git_log.fish
Only in /Users/nv4re/.config/fish/functions: _fzf_search_git_status.fish
Only in /Users/nv4re/.config/fish/functions: _fzf_search_history.fish
Only in /Users/nv4re/.config/fish/functions: _fzf_search_processes.fish
Only in /Users/nv4re/.config/fish/functions: _fzf_search_variables.fish
Only in /Users/nv4re/.config/fish/functions: _fzf_wrapper.fish
Only in /Users/nv4re/.config/fish/functions: fisher.fish
Only in /Users/nv4re/.config/fish/functions: fzf_configure_bindings.fish
Only in /Users/nv4re/Documents/Personal/nv4re/nvm.fish: tests
Only in /Users/nv4re/.config/fish: themes

@jorgebucaran
Copy link
Owner

Intriguing. For the other questions, I'm going to assume you're only using Fisher and nvm.fish with no custom conf.d/ snippets. The next best thing I can offer is hopping on a hangout to debug this in real-time. The plan would be to trace the nvm use code path and see exactly where it's failing.

Now, if you want to tackle it yourself, you'll need to uninstall nvm.fish first, clone this repo, install your clone with

fisher install path/to/clone

and then start inserting echo statements in the nvm use code path to pinpoint where the issue is happening.

Let me know how you would like to proceed.

@PThorpe92
Copy link

Ran into this same issue on an employees WSL ubuntu fresh install (also didn't have a system node, v12.x.x from apt repo is pretty much useless in this situation).

For anyone else, (very) temporary/jank fix is just to add nvm install vxx.x.x into end of ~/.config/fish/config.fish and it doesn't re-download it, just gives now using Node vxx.x.x when shell starts up. and version can be changed/sourced easily enough.

I tried to reproduce this as well with no luck, and I had just so happened to do 2 fresh debian installs in the past week that both were setup with nvm, fish, fisher and this was the only one that had this issue.

@jorgebucaran
Copy link
Owner

Thanks. Can't repro as well. This is most definitely an issue on the user's end, not with nvm.fish, which has been pretty much stable for years. I'm happy to hop on a call with @NV4RE or @PThorpe92 to help debug since I don't have access to a system with the issue.

@NV4RE
Copy link
Contributor Author

NV4RE commented Sep 8, 2024

I've identified the underlying issue:

The regex pattern "v\d.+" used to match version directories is overly broad and can mistakenly match usernames containing "v" followed by digits.

For example, my username "nv4re" triggers a false match, causing the entire path "/Users/nv4re/.local/share/nvm/v16.20.2" to be matched instead of just the version directory "v16.20.2". This leads to incorrect output from the _nvm_list function, potentially causing version management issues.

@jorgebucaran
Copy link
Owner

Great find, wow! If you happen to have a fix, send it over, otherwise, I'll handle this tomorrow. Thank you so much.

@NV4RE
Copy link
Contributor Author

NV4RE commented Sep 8, 2024

Great find, wow! If you happen to have a fix, send it over, otherwise, I'll handle this tomorrow. Thank you so much.

#227 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants