diff --git a/scripts/find-node.sh b/scripts/find-node.sh index 2c7e894dd048d7..3c06f48aa02875 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