From f2c58ff0916ce2af96830f6dfd6990fdd36210ba Mon Sep 17 00:00:00 2001 From: Chenglin97 Date: Wed, 18 Mar 2026 01:55:12 -0700 Subject: [PATCH] fix(installer): load nvm before Node.js version check On systems where nvm manages Node.js, the installer was detecting the system-installed Node (e.g. /usr/bin/node v8) because /usr/bin appears before ~/.nvm/versions/node/.../bin on PATH in non-interactive shells. This caused check_node() to fail on the stale system binary and trigger install_node(), which overwrote the user's nvm environment unnecessarily. Fix: add try_load_nvm() that sources ~/.nvm/nvm.sh (with --no-use to avoid side effects) and activates the nvm default alias before check_node runs. If nvm is not installed, try_load_nvm() is a no-op. Fixes #49556 --- scripts/install.sh | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/scripts/install.sh b/scripts/install.sh index 70c68bf703c..61b841e0ea7 100755 --- a/scripts/install.sh +++ b/scripts/install.sh @@ -1395,6 +1395,21 @@ ensure_default_node_active_shell() { return 1 } +try_load_nvm() { + # Source nvm before checking Node.js so the installer uses the nvm-managed + # version rather than a system-installed Node that may be too old. + # This is a no-op if nvm is not installed or already loaded. + local nvm_dir="${NVM_DIR:-$HOME/.nvm}" + if [[ -s "${nvm_dir}/nvm.sh" ]]; then + # shellcheck source=/dev/null + . "${nvm_dir}/nvm.sh" --no-use + # Activate the default/current nvm Node version if one is set + if command -v nvm >/dev/null 2>&1; then + nvm use default --silent 2>/dev/null || nvm use node --silent 2>/dev/null || true + fi + fi +} + check_node() { if command -v node &> /dev/null; then NODE_VERSION="$(node_major_version || true)" @@ -2340,6 +2355,11 @@ main() { install_homebrew # Step 2: Node.js + # Proactively load nvm if available so the installer picks up the nvm-managed + # Node instead of a stale system Node (e.g. /usr/bin/node v8) that appears + # earlier on PATH. Without this, check_node() fails on the system binary and + # install_node() runs unnecessarily, overwriting the user's nvm environment. + try_load_nvm if ! check_node; then install_node fi