From 000492671c66d029333f75e8d498be334b4211e0 Mon Sep 17 00:00:00 2001 From: CanbiZ <47820557+MickLesk@users.noreply.github.com> Date: Tue, 4 Nov 2025 15:23:01 +0100 Subject: [PATCH] Improve Node.js setup for Debian systems Enhances the setup_nodejs function to remove Debian-packaged Node.js if present, set APT preferences to prioritize NodeSource packages, and verify npm availability after installation. These changes help avoid conflicts between Debian and NodeSource Node.js versions and ensure npm is properly installed. --- misc/tools.func | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/misc/tools.func b/misc/tools.func index 6dfedefd5..2fea2d886 100644 --- a/misc/tools.func +++ b/misc/tools.func @@ -3321,6 +3321,13 @@ function setup_nodejs() { # Clean up legacy installations (nvm, etc.) cleanup_legacy_install "nodejs" + # Remove Debian's nodejs if present (conflicts with NodeSource) + if dpkg -l | grep -q "^ii.*nodejs.*dfsg"; then + $STD msg_info "Removing Debian-packaged Node.js (conflicts with NodeSource)" + $STD apt purge -y nodejs libnode* 2>/dev/null || true + $STD apt autoremove -y 2>/dev/null || true + fi + ensure_dependencies curl ca-certificates gnupg # Prepare repository (cleanup + validation) @@ -3335,10 +3342,21 @@ function setup_nodejs() { return 1 } + # Set APT priority to prefer NodeSource over Debian repos + cat >/etc/apt/preferences.d/nodesource <<'EOF' +Package: nodejs +Pin: origin deb.nodesource.com +Pin-Priority: 600 + +Package: * +Pin: origin deb.nodesource.com +Pin-Priority: 600 +EOF + # Wait for repo to settle sleep 2 - # Install Node.js with retry logic + # Install Node.js with retry logic (explicit version to avoid Debian repo) install_packages_with_retry "nodejs" || { msg_error "Failed to install Node.js ${NODE_VERSION} from NodeSource" return 1 @@ -3354,6 +3372,12 @@ function setup_nodejs() { INSTALLED_NODE_VERSION=$(node -v 2>/dev/null | grep -oP '^v\K[0-9]+' || echo "0") verify_tool_version "Node.js" "$NODE_VERSION" "$INSTALLED_NODE_VERSION" || true + # Verify npm is available (should come with NodeSource nodejs) + if ! command -v npm >/dev/null 2>&1; then + msg_error "npm not found after Node.js installation - repository issue?" + return 1 + fi + # Update to latest npm (with version check to avoid incompatibility) local NPM_VERSION NPM_VERSION=$(npm -v 2>/dev/null || echo "0")