diff --git a/scripts/find-node.sh b/scripts/find-node.sh index 84e930a12d31d4..5d6d2c460e9dc0 100755 --- a/scripts/find-node.sh +++ b/scripts/find-node.sh @@ -19,12 +19,16 @@ fi # Define NVM_DIR and source the nvm.sh setup script [ -z "$NVM_DIR" ] && export NVM_DIR="$HOME/.nvm" +# Source nvm with '--no-use' and then `nvm use` to respect .nvmrc +# See: https://github.com/nvm-sh/nvm/issues/2053 if [[ -s "$HOME/.nvm/nvm.sh" ]]; then # shellcheck source=/dev/null - . "$HOME/.nvm/nvm.sh" + . "$HOME/.nvm/nvm.sh" --no-use + nvm use 2> /dev/null || nvm use default elif [[ -x "$(command -v brew)" && -s "$(brew --prefix nvm)/nvm.sh" ]]; then # shellcheck source=/dev/null - . "$(brew --prefix nvm)/nvm.sh" + . "$(brew --prefix nvm)/nvm.sh" --no-use + nvm use 2> /dev/null || nvm use default fi # Set up the nodenv node version manager if present