jorgebucaran / nvm.fish

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

Using nvm.fish from .envrc #229

Open oschrenk opened 1 week ago

oschrenk commented 1 week ago

This is not reporting a defect more of a curiosity I think , so feel free to ignore/close

I am looking for advice on how to run nvm.fish from an .envrc file loaded via direnv.

The .envrc file:

[ -s "$HOME/.config/fish/functions/nvm.fish" ] && fish -c "nvm list; nvm use v16.16.0";

But nvm seems to default to the system version. The output:

direnv: loading ~/Projects/acme/.envrc
     system
 ▶ v16.16.0 lts/gallium
Now using Node v22.8.0 (npm 10.8.2) /opt/homebrew/Cellar/node/22.8.0/bin/node

While nvm list does pick up the right version. The subsequent nvm use seems to ignore it. I am pretty sure this has to do with some shell shenanigans, as running nvm use v16.16.0 directly works.

Interestingly enough, when using a wrong version:

[ -s "$HOME/.config/fish/functions/nvm.fish" ] && fish -c "nvm list; nvm use foooo";

will result in

direnv: loading ~/Projects/acme/.envrc
     system
 ▶ v16.16.0 lts/gallium
nvm: Can't use Node "foooo", version must be installed first

so nvm does parse the version but for some reason doesn't use it in this context.

oschrenk commented 1 week ago

Ah. Using search term direnv showed me

https://github.com/jorgebucaran/nvm.fish/issues/131

It seems that nvm 2.x is not working with direnv

oschrenk commented 1 week ago

For that matter it also means i can't run it via https://taskfile.dev I think.