lukechilds / zsh-nvm

Zsh plugin for installing, updating and loading nvm
MIT License
2.22k stars 112 forks source link

Lazy: Npm without other globals not available without loading nvm #4

Closed SimenB closed 8 years ago

SimenB commented 8 years ago

I think this is the issue, not sure though...

I set this up on my work machine, and just nvm install 6.4 gives the following from which node in a new shell:

node () {
        unset -f node nvm
        _zsh_nvm_load
        node "$@"
}

Running npm i -g npm then a new session made no difference. I then installed npm-check-update and typings, which gave me:

node () {
        unset -f ncu node npm npm-check-updates typings nvm
        _zsh_nvm_load
        node "$@"
}

which npm gave me npm not found up until the last one.

Not sure why, but maybe it'll give you a starting point for where to look 😄

lukechilds commented 8 years ago

Sorry a bit confused, when did you get npm not found, after you installed npm?

lukechilds commented 8 years ago

Ok, found the issue, for some insane reason npm gets ignored when node and npm are the only binaries. For example:

% ls $NVM_DIR/versions/*/*/bin/*(N)
/Users/lukechilds/.lazyload-test/versions/node/v6.4.0/bin/node
/Users/lukechilds/.lazyload-test/versions/node/v6.4.0/bin/npm

% ls $NVM_DIR/versions/*/*/bin/*(N) | xargs basename
node

But then if you install a module:

% ls $NVM_DIR/versions/*/*/bin/*(N)
/Users/lukechilds/.lazyload-test/versions/node/v6.4.0/bin/node
/Users/lukechilds/.lazyload-test/versions/node/v6.4.0/bin/npm
/Users/lukechilds/.lazyload-test/versions/node/v6.4.0/bin/package

% ls $NVM_DIR/versions/*/*/bin/*(N) | xargs basename
node
npm
package

Working on a fix...

lukechilds commented 8 years ago

Doh! Just needed to set max-args to 1 on xargs:

% ls $NVM_DIR/versions/*/*/bin/*(N)
/Users/lukechilds/.lazyload-test/versions/node/v6.4.0/bin/node
/Users/lukechilds/.lazyload-test/versions/node/v6.4.0/bin/npm

% ls $NVM_DIR/versions/*/*/bin/*(N) | xargs basename
node

% ls $NVM_DIR/versions/*/*/bin/*(N) | xargs -n1 basename
node
npm

Should be fixed as of https://github.com/lukechilds/zsh-nvm/commit/1be9149af66b7324adbfff0d43287f463009b194. which npm now works after a fresh install:

% which npm
npm () {
        unset -f node npm nvm
        _zsh_nvm_load
        npm "$@"
}

Thanks for taking the time to report 👍

SimenB commented 8 years ago

No problem, thanks for the quick fix!