lukechilds / zsh-nvm

Zsh plugin for installing, updating and loading nvm

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Lazy: Take precedence over preinstalled node

SimenB opened this issue Β· comments

I installed yarn through brew instead of npm (as it's recommended that way), but since Yarn in brew depends on node, that gets installed as well, and using node or npm doesn't load nvm any more.

Hmmn, it would appear that the node and npm binaries are taking priority over the lazy loader functions.

Could you start a new session and let me know what which node outputs. Also if you have any globally installed modules running which <module name> would be helpful. Thanks :)

I just installed yarn through brew and I get:

$ which node
/usr/local/bin/node

So the brew node binary does have a higher priority than the lazy loader node function. I'm not quite sure why, I thought functions should have priority over PATH binaries. If I create a function in the session it does take priority:

$ which node
/usr/local/bin/node
$ node() { echo node }
$ which node
node () {
	echo node
}

If I brew uninstall yarn, node and npm, then npm install -g yarn it works.

Since you can reproduce, I don't need to run which? It's on another machine, so it's just a bit more work than no work at all πŸ˜†

Yep, I've done it haha

You can also disable NVM_LAZY_LOAD and then zsh-nvm and brew node can live together happily.

So you need to choose:

  • brew install yarn and NVM_LAZY_LOAD=false
  • npm install -g yarn and NVM_LAZY_LOAD=true

To clarify, the issue appears to be caused by brew node, I'm not quite sure how it's overriding the lazy load function. If I can figure out I may be able to get them to work together but I would suggest using one of the two options above :)

Found the conflict!

Working on a fix...

It was caused by the fix for the issue you pointed out before when the name of a global node module is already in use.

I should be able to just whitelist node and npm from that list as we always know we want our versions to take precedence.

So it's kinda my fault? Cool! 😁

But yeah, adding node and npm to cmds at creation time makes sense to me, at least

Haha no it's not your fault, you just seem to be really good at finding edge cases in my code πŸ˜†

Should have a fix shortly...

I've updated the fix from the other issue to specifically check for aliases rather than any binary/alias/function. That seems to have done the job.

@SimenB Let me know if this works for you :)

It works! Thanks.

I did figure out I could do brew install yarn --ignore-dependencies. I then get env: node: No such file or directory 😁 Is it possible for me to append a custom command to the array you check? Say I did NVM_LOAD_CMDS=(yarn) or something?

Great, thanks for raising the issue!

Sorry, I'm not too sure what you're asking for re the array. If you want to lazy load yarn I don't think that's gonna be possible because that's all handled with homebrew symlinks.

I don't want to lazy load yarn, but yarn depends on node, which is lazy loaded. So I want your same wrapper to include yarn (that is, load up nvm so Node is loaded)

Ahhhh, I see.

Yeah that would be possible although I'm kinda reluctant to do that. It's not a very common use case, the issue is occurring because you're using two different package managers to install node modules. The ideal solution would be to just use npm for everything, although yarn do make good arguments against it.

I think a better solution may be for me to manually check if yarn is installed and add that to the array. Other people will likely have this issue with yarn so it'll be nice if it works automatically. And it's unlikely to occur in any other scenarios so doesn't really warrant an extra option.

Yeah, that's fine as well πŸ˜„

I'll take a look at that tomorrow :)

You can track progress here: #16

No rush, thank you!