FabioAntunes / fish-nvm

nvm wrapper for fish-shell
MIT License
511 stars 20 forks source link

Default version / .nvmrc not working #11

Closed jklmli closed 7 years ago

jklmli commented 7 years ago

Not sure why this is happening - nvm works well normally, but it's a pain to manually select a specific version every time.

A new shell starts up with a node version of 'none'. I've manually set a default version through nvm and verified that it works correctly in bash.

I don't have a custom $NVM_DIR.

FabioAntunes commented 7 years ago

Thanks @jiaweihli, will have a look and let you know.

Lordnibbler commented 7 years ago

same problem! fish 2.4

i cheated by:

echo 'default' > ~/.nvmrc
echo 'nvm use' > ~/.config/fish.config

but this is not ideal

jorgebucaran commented 7 years ago

@jiaweihli Just a reminder that there is also:

I use verman personally.

FabioAntunes commented 7 years ago

@jiaweihli have you tried running nvm alias default 6.9.0 this will set your default node version to 6.9.0 (feel free to chose another one) whenever you open a new terminal?

@Lordnibbler why are you putting the .nvmrc on your home path ~/ ? that file should be inside your project folder. Let's imagine you are working on project that requires a very specific node version, let's say v4.4.4 you would do something like this:

cd /path/to/your/project
echo "4.4.4" > .nvmrc

Et voilà now when you use node inside this folder, it will pick the .nvmrc and use that specific version.

jklmli commented 7 years ago

@FabioAntunes Yes, I've done that and it works correctly in bash - but not in fish.

jklmli commented 7 years ago

It does work correctly if I set nvm use default in ~/.config/fish/config.fish, but this adds an extra 1 second overhead to every new terminal.

jorgebucaran commented 7 years ago

@FabioAntunes Correct me if I am wrong, but isn't this precisely how nvm works? The tradeoff is between this extra second on every terminal or the manual extra step to run nvm yourself before using node.

FabioAntunes commented 7 years ago

@jbucaran That's why I created this so whenever you use node, npm, nvm and now also yarn, it checks if there's a node already sourced, if not either source a local .nvmrc or source the default alias.

@jiaweihli I'm really sorry, but are you sure you have nvm properly installed? I have been using this since day one and I have never had any problems. I also have a couple of friends who use this and everything works for them. I know this sounds cliché, but could you please uninstall nvm and install it again using fisherman

jklmli commented 7 years ago

Sorry for radio silence. I've tried installing fisherman nvm as well as nvm, no luck. At this point I'm just eating the extra manual work 😞

Let me know if there's any logs I can send you that would help you debug this.

jorgebucaran commented 7 years ago

@jiaweihli Installing fisherman again will not fix anything, since fisherman is just a single function that goes into your ~/.config/fish/functions directory. There's nothing special or antyhing that deviates from standard fish, so perhaps there is an issue with your fish? :)

Can you try using fnm / verman and let me know if the problem goes away?

fanaugen commented 7 years ago

I have the exact same problem as @jiaweihli. fnm works fine, but I was kind of hoping to be able to continue using NVM, because I use it on bash also.

If I understand @jbucaran’s comment above correctly, the 1 second that it takes NVM to run seems inevitable anyway? I certainly experience a 1 second lag when starting up bash, where the NVM script is configured to run.

jorgebucaran commented 7 years ago

@fanaugen I'm a bit confused. This is fisherman/nvm. I understand this plugin was created so one can keep using nvm, as usual, with fish.

Before this plugin, I made fnm, which does things differently, but also supports .nvmrc to ease with the migration. It's still supported and it has many users.

Then, I made verman which is a configuration-only, much simpler approach, and it's what I use nowadays.

@FabioAntunes Is nvm/node for you? Might want to upgrade your fish to 2.5 to see if anything breaks by the way.

EDIT:

I certainly experience a 1 second lag when starting up bash, where the NVM script is configured to run.

1 second lag, give or take is inevitable, but tapping into fish function autoloading, we can delay this lag to the moment we actually intend to use node, thus solving the slow shell start problem.

This is implemented by creating a fish wrapper function around the node/npm (now yarn too?) binaries.

This is how fnm and verman works and to some extend, fisherman/nvm, but you'll have to ask Fabio who is the author of fisherman/nvm for the details.

fanaugen commented 7 years ago

Sorry for creating confusion. I was just trying to say that, as @jiaweihli pointed out, fisherman/nvm doesn’t "remember" the node version used across shell sessions. To reproduce:

Not sure whether this is intended behaviour, but the --no-use on this line suggests that it might be.

balupton commented 7 years ago

this worked fine for me:

balupton@balbook ~> node -v
fish: Unknown command 'node'

balupton@balbook ~> fisher nvm
Installing 1 plugin/s
OK Fetch nvm github.com/fisherman/nvm
Done in 3s 691ms

balupton@balbook ~> node -v
Now using node v7.8.0 (npm v4.4.4)
v7.8.0

then in a new terminal:

balupton@balbook ~> node -v
Now using node v7.8.0 (npm v4.4.4)
v7.8.0
tanc commented 7 years ago

I also have this problem where opening a new shell will not switch to the default node version. I've uninstalled and re-installed nvm and fisher nvm but its still not working.

Following the steps that @balupton mentioned above I also get a working node version, but not the version I have specified as my default when I used nvm alias default lts/argon

New terminal always shows:

$ node --version
v7.10.0

Then I have to do:

$ nvm use default
Now using node v4.8.3 (npm v2.15.11)
FabioAntunes commented 7 years ago

This is getting really frustrating, I'm not able to reproduce this on my machine. I'm going to format my machine during the weekend and with a fresh install, maybe I will be able to reproduce this.

On 24 May 2017 at 16:15, Tanc notifications@github.com wrote:

I also have this problem where opening a new shell will not switch to the default node version. I've uninstalled and re-installed nvm and fisher nvm but its still not working.

Following the steps that @balupton https://github.com/balupton mentioned above I also get a working node version, but not the version I have specified as my default when I used nvm alias default lts/argon

New terminal always shows:

$ node --version v7.10.0

Then I have to do:

$ nvm use default Now using node v4.8.3 (npm v2.15.11)

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/fisherman/nvm/issues/11#issuecomment-303755972, or mute the thread https://github.com/notifications/unsubscribe-auth/ACbUIcMZRFwH9-99UDP7RTPzBlzxAMflks5r9El1gaJpZM4LcBUO .

FabioAntunes commented 7 years ago

@tanc can you do me a favour? Run echo $PATH and paste the output please.

tanc commented 7 years ago
$ echo $PATH
/Users/tanc/.rvm/gems/ruby-2.4.0/bin /Users/tanc/.rvm/gems/ruby-2.4.0@global/bin /Users/tanc/.rvm/rubies/ruby-2.4.0/bin /Users/tanc/.rvm/bin /bin /Users/tanc/.composer/vendor/bin /Users/tanc/.fzf/bin /usr/local/bin /usr/bin /bin /usr/sbin /sbin
FabioAntunes commented 7 years ago

@tanc can you also run which node on a freshly opened terminal

@jiaweihli @Lordnibbler @fanaugen

Sorry for this late request, if you guys are still using this Package, could you guys run echo $PATH on a fresh fish terminal, but make sure you guys remove any cheating i.e. nvm use inside the fish.config

tanc commented 7 years ago
$ which node
/usr/local/bin/node
FabioAntunes commented 7 years ago

Ok, I discovered your problem @tanc, you have node installed outside of nvm, that makes node global available. So since you already have node on your $PATH, fish-nvm doesn't source nvm. One solution is either uninstalled it and just use nvm, or wait a couple of days. I'm working on fix for this, so even if node exists we always source nvm

tanc commented 7 years ago

Fantastic, thanks @FabioAntunes

I'll wait a couple of days and test your fix :)

FabioAntunes commented 7 years ago

@tanc run fisher update nvm and give it a try

tanc commented 7 years ago

Brilliant! Works great after update

jklmli commented 7 years ago

This removed the delay-on-new-terminal issue I was having as well, but I noticed an issue:

⋊> kevin at origin in ~ since Tue May 30 12:20:41
$ nvm current
system
⋊> kevin at origin in ~ since Tue May 30 12:20:43
$ cat ~/Desktop/test.js
#! /usr/bin/env node

console.log('hello world')
⋊> kevin at origin in ~ since Tue May 30 12:20:46
$ ~/Desktop/test.js
hello world
⋊> kevin at origin in ~ since Tue May 30 12:20:48
$ nvm current
system
⋊> kevin at origin in ~ since Tue May 30 12:20:51
$ node --version
Now using node v6.10.2 (npm v3.10.10)
v6.10.2
⋊> kevin at origin in ~ since Tue May 30 12:20:55
$ nvm current
v6.10.2
⋊> kevin at origin in ~ since Tue May 30 12:20:58
$ ~/Desktop/test.js
hello world
⋊> kevin at origin in ~ since Tue May 30 12:21:01
$ nvm current
v6.10.2

It looks like the node switching logic has been moved to the first instance of running node on the command line. I notice the same delay when I run node --version for the first time, but not the second time.

If you're running a shell/python script that calls out to node, it might not be using the default version (if you just opened a new shell).

FabioAntunes commented 7 years ago

Yep that's the point, to only source node when we need.

You can either keep doing what you were doing, source nvm on shell init. Or you can create a command called node on some directory of yours.

$ mkdir ~/mycommands/
$ cd ~/mycommands/
$ touch node
$ chmod +x node

Edit the file and paste this:

#! /usr/bin/env fish

__nvm_run "node" $argv

Add this line to your config.fish set -g -x PATH ~/mycommands $PATH

You can do it manually or by just running this

$ echo "set -g -x PATH ~/mycommands $PATH"  >> ~/.config/fish/config.fish
saneef commented 7 years ago

Also, in the freshly loaded shell. The globally installed packages for default will be missing; unless run node or nvm use default once.

richardpringle commented 7 years ago

Hey guys,

I'm on nvm 0.33.2 and I installed nvm through the zsh plugin. Default works fine, nvm use works fine, but the .nvmrc file does not work.

I have a bunch of node versions all over the place so that might be my problem but when I call node, it's definitely using the version supplied by nvm.

any ideas?

FabioAntunes commented 7 years ago

@richardpringle check if in any of these files ~/.bash_profile, ~/.zshrc, ~/.profile, or ~/.bashrc

nvm is being autoloaded, this is the bit that does that:

export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && . "$NVM_DIR/nvm.sh" # This loads nvm

if so you need to remove that.

richardpringle commented 7 years ago

@FabioAntunes, thanks for the response!

I just realized that I'm in the fisherman/nvm instead of creationix/nvm... woops!

It actually appears as though I needed to call nvm use (with no arguments) once in the folder with the .nvmrc file and it started working after that.

^^^ I guess this is for anyone who stumbles upon this issue from a google search even if you aren't using fisherman.

weedgrease commented 7 years ago

I'm having this issue and I'm a bit confused. I've removed any instance of nvm sourcing from the files mentioned above and it doesn't seem to change anything.

I currently can't even call which when I first open my shell. Calling node --version prints out 6.9.2 which is what I would expect, but calling which only works if I have nvm use default in my config.fish.

kevin ~ > which
env: node: No such file or directory
kevin ~ > which node
env: node: No such file or directory
kevin ~ > nvm use default
Now using node v6.9.2 (npm v3.10.9)
kevin ~ > which node
/Users/kevin/.nvm/versions/node/v6.9.2/bin/node
kevin ~ > which
usage: which [-as] program ...
richardpringle commented 7 years ago

I actually soft linked to the same node version as my default alias in /usr/local/bin so I can still use node from other terminals. I believe the reason that which node isn't working for you is because the node command doesn't actually call an executable directly, it calls a shell function that uses nvm path variables to figure out which executable can be called.

I'm sure one of the other commenters in this issue will correct me if I'm wrong.

lukiano commented 6 years ago

Is there any update on this issue? On a new shell, if I go to a folder with .nvmrc, calling node loads the correct version (as specified in that file), but if then I go to another folder with .nvmrc pointing to a different version, executing node does not switch to that version, I have to execute nvm use first.

FabioAntunes commented 6 years ago

@lukiano that's the default behaviour check https://github.com/creationix/nvm#deeper-shell-integration

If you want you can create some sort of script that listens for folder changes and checks if there's a .nvm

lukiano commented 6 years ago

Ok thanks, I didn't know that was the right behaviour. I'd certainly have a script that listens for folder changes, but also performs the lazy loading. It looks like the core of the magic is in __nvm_run.fish ? Anyway I'll take a deeper look.