Skip to content

Commit df8ab93

Browse files
[Fix] 'nvm exec' no longer prints error about '-q' being an invalid option
The `NVM_CD_FLAGS` variable is assigned a value if nvm is being run in zsh, so that `cd`'ing around won't print any error messages. This flag, however, is not compatible with bash's `cd` built-in. Because this variable was exported, it meant that a user running zsh would be unable to run `nvm exec ...` commands without encountering errors. This issue manifests itself in the following manner: ```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. ``` > in this case, node 16.14.0 _is_ installed. By not exporting the variable, it will not be visible inside the `nvm-exec` script, and the `NVM_CD_FLAGS` will be assigned fresh on each run when the `nvm.sh` file is sourced, and commands like this will be successful.
1 parent ef3b20c commit df8ab93

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

Diff for: nvm.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -332,7 +332,7 @@ nvm_install_latest_npm() {
332332
# Make zsh glob matching behave same as bash
333333
# This fixes the "zsh: no matches found" errors
334334
if [ -z "${NVM_CD_FLAGS-}" ]; then
335-
export NVM_CD_FLAGS=''
335+
NVM_CD_FLAGS=''
336336
fi
337337
if nvm_is_zsh; then
338338
NVM_CD_FLAGS="-q"

0 commit comments

Comments
 (0)