Nvm: Attempting to source nvm from within a ruby script does not seem to use parent shell

Created on 22 Jul 2017  ·  15Comments  ·  Source: nvm-sh/nvm

  • Operating system and version:
    MacOS 10.12.5

  • nvm debug output:
    no debug output, the script won't load

  • nvm ls output:
    no ls output, the script won't load

  • How did you install nvm? (e.g. install script in readme, homebrew):
    I don't remember. Probably zsh-nvm

  • What steps did you perform?
    I've added

  system %{
    . ~/.nvm/nvm.sh
    nvm use 4.5.0
    npm install
  }

to a Rakefile. Running the rakefile results in the following error:

/Users/tylerthrailkill/.nvm/nvm.sh: line 27: cd: -q: invalid option
cd: usage: cd [-L|-P] [dir]
N/A: version "4.5.0 -> N/A" is not yet installed.

With my own debugging I don't understand why -q is not a valid option, since I'm running in a zsh, and I've verified SHELL is zsh.

  • What happened?
    nvm won't load

  • What did you expect to happen?
    nvm to load, since I'm running the rakefile from a zsh, it should run consistently in that shell.

  • Is there anything in any of your profile files (.bashrc, .bash_profile, .zshrc, etc) that modifies the PATH?
    Yes, lots, but I've verified through modifying the nvm.sh file to printenv to show that I'm in the proper shell with the property stuff set. Here is that output

AUTOJUMP_ERROR_PATH=/Users/tylerthrailkill/Library/autojump/errors.log
MANPATH=/Users/tylerthrailkill/.nvm/versions/node/v7.3.0/share/man:/usr/local/man:/usr/local/mysql/man:/usr/local/git/man:
TERM_PROGRAM=iTerm.app
NVM_CD_FLAGS=-q
AUTOJUMP_SOURCED=1
TERM=xterm-256color
SHELL=/usr/local/bin/zsh
CLICOLOR=true
TMPDIR=/var/folders/mk/lvf9cfc57ss2fym_pdcz_t400000gn/T/
GRADLE_HOME=/Users/tylerthrailkill/Applications/ActiveVersions/Gradle
Apple_PubSub_Socket_Render=/private/tmp/com.apple.launchd.j6fEZlOD3E/Render
TERM_PROGRAM_VERSION=3.0.15
TERM_SESSION_ID=w0t3p0:F59F1C90-B51C-4D10-A132-EE9D008A7CA9
PHANTOM_JS=/Users/tylerthrailkill/Applications/ActiveVersions/PhantomJS
ZSH=/Users/tylerthrailkill/.oh-my-zsh
USER=tylerthrailkill
SSH_AUTH_SOCK=/private/tmp/com.apple.launchd.OhYNsonF3t/Listeners
__CF_USER_TEXT_ENCODING=0x1F5:0x0:0x0
VIRTUAL_ENV_DISABLE_PROMPT=1
PAGER=less
DOTFILES=/Users/tylerthrailkill/.dotfiles
LSCOLORS=exfxcxdxbxegedabagacad
PATH=/Users/tylerthrailkill/.nvm/versions/node/v7.3.0/bin:/Users/tylerthrailkill/Applications/ActiveVersions/Maven/bin:/Users/tylerthrailkill/Applications/ActiveVersions/Gradle/bin:/Users/tylerthrailkill/Applications/ActiveVersions/PhantomJS/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin
NVM_NODEJS_ORG_MIRROR=https://nodejs.org/dist
PWD=/Users/tylerthrailkill/Documents/dev/code/borrower-wallet-ui
JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.8.0_73.jdk/Contents/Home
EDITOR=vim
LANG=en_US.UTF-8
ITERM_PROFILE=Tyler
XPC_FLAGS=0x0
NVM_LAZY_LOAD=true
XPC_SERVICE_NAME=0
M2_HOME=/Users/tylerthrailkill/Applications/ActiveVersions/Maven
SHLVL=2
HOME=/Users/tylerthrailkill
COLORFGBG=15;0
ITERM_SESSION_ID=w0t3p0:F59F1C90-B51C-4D10-A132-EE9D008A7CA9
LESS=-R
LOGNAME=tylerthrailkill
LC_CTYPE=en_US.UTF-8
NVM_BIN=/Users/tylerthrailkill/.nvm/versions/node/v7.3.0/bin
NVM_IOJS_ORG_MIRROR=https://iojs.org/dist
PROMPT_EOL_MARK=
_=/usr/bin/printenv
needs followup zsh shell oh-my-zsh

Most helpful comment

Ok, give me a few minutes then.

All 15 comments

What zsh options do you have? Specifically what's the output of setopt? zsh options often break tools that don't run in a subshell.

I'd also try disabling omz; it will likely work fine - which implicates one of omz's options.

setopt output

❯ setopt                                                                                                                                                                           
alwaystoend
autocd
autopushd
completeinword
correct
extendedhistory
noflowcontrol
nohistbeep
histexpiredupsfirst
histignorealldups
histignoredups
histignorespace
histreduceblanks
histverify
ignoreeof
incappendhistory
interactive
interactivecomments
localoptions
localtraps
longlistjobs
monitor
promptsubst
pushdignoredups
pushdminus
sharehistory
shinstdin
zle

I disabled oh-my-zsh and still get the error

Oh wait, nope. I had to start a new session, not just source zshrc. Looks like disabling oh-my-zsh got rid of the error. But I need a way for this rakefile to work for anyone anywhere.

I will try to reproduce it, but the fastest method is for you to do a binary search on that option list, until you find out exactly which option is breaking it - then I can quickly work around it.

Ok, give me a few minutes then.

(You can ofc skip the stock zsh options)

ofc? and I tried unsetting every option but I still get the error

```/Users/tylerthrailkill/.nvm/nvm.sh: line 30: cd: -q: invalid option
cd: usage: cd [-L|-P] [dir]
N/A: version "4.5.0 -> N/A" is not yet installed.

You need to run "nvm install 4.5.0" to install it before using it.
N/A: version "4.5.0 -> N/A" is not yet installed.

You need to run "nvm install 4.5.0" to install it before using it.
^Crake aborted!

/Users/tylerthrailkill/Documents/dev/code/borrower-wallet-ui/Rakefile:28:in `' /Users/tylerthrailkill/Documents/dev/code/borrower-wallet-ui/Rakefile:28:inblock in Tasks: TOP => default => setup
(See full trace by running task with --trace)

~/Documents/dev/code/borrower-wallet-ui ${prompt_pure_vcs_info[branch]}${prompt_pure_git_dirty}
${PURE_PROMPT_SYMBOL:-❯} ^C^C^C^C^C^C

~/Documents/dev/code/borrower-wallet-ui ${prompt_pure_vcs_info[branch]}${prompt_pure_git_dirty}
${PURE_PROMPT_SYMBOL:-❯} setopt
interactive
shinstdin
```

Do I need to unset the options in omzsh somehow and then create a new session to test each option?

and also, if I do disable oh-my-zsh I get these errors.

N/A: version "4.5.0 -> N/A" is not yet installed.

which I would think shouldn't be happening.

Ok, it's the zsh-nvm plugin doing something.

("ofc" means "of course")

If you uninstall zsh-nvm, with your normal omz, what happens?

Everything works perfectly if I remove zsh-nvm from plugins=(otherpluginshere...)

In that case, it sounds like it's a bug in zsh-nvm, and not in this project - can you file it there, and link it, and close this one after doing that?

Yes I can. Thank you for your help.

Was this page helpful?
0 / 5 - 0 ratings