-
-
Notifications
You must be signed in to change notification settings - Fork 8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Fix] 'nvm exec' no longer prints error about '-q' being an invalid option #2800
Conversation
this will not regress it because the variable is still being assigned a value; it's just not being exported. When it's exported, it means that it's going to be assigned to all child processes that are called from this point on. so when the |
Is an alternative for nvm-exec to always unset |
that was the fix that I was originally going to propose but it doesn't address the root cause of the bug. The codebase only references the if explicitly |
@spikegrobstein any interest in updating to that approach? |
I totally didn't notice this reply and I totally forgot about this. I'll get this updated later today when I have time and push the requested change. |
…sers the `nvm.sh` file assigns and exports an `NVM_CD_FLAGS` variable if it was sourced from a zsh shell. the fact that it's exported means that it'll be assigned in all child processes, including the `nvm-exec` script, which uses bash as the interpreter. Bash's `cd` command doesn't have a `-q` flag, so if the `NVM_CD_FLAGS` is assigned `-q`, the script will error out and incorrectly claim that the node version isn't installed. this also manifests itself in the `nvm exec` command. Example: ```console $ nvm exec 16.14.0 npm --version Running node v16.14.0 (npm v8.3.1) /Users/<ME>/.nvm/nvm.sh: line 28: cd: -q: invalid option cd: usage: cd [-L|[-P [-e]] [-@]] [dir] both the tree and the node path are required N/A: version "v16.14.0 -> N/A" is not yet installed. You need to run "nvm install v16.14.0" to install it before using it. ``` To address this, we unset the `NVM_CD_FLAGS` at the start of the `nvm-exec` script, before loading `nvm.sh`.
df8ab93
to
aa46404
Compare
I replaced my previous commit with a new fix/explanation and rebased against Let me know how this is. |
the
nvm.sh
file assigns and exports anNVM_CD_FLAGS
variable if itwas sourced from a zsh shell. the fact that it's exported means that
it'll be assigned in all child processes, including the
nvm-exec
script, which uses bash as the interpreter.
Bash's
cd
command doesn't have a-q
flag, so if theNVM_CD_FLAGS
is assigned
-q
, the script will error out and incorrectly claim thatthe node version isn't installed.
this also manifests itself in the
nvm exec
command.Example:
To address this, we unset the
NVM_CD_FLAGS
at the start of thenvm-exec
script, before loadingnvm.sh
.