fix(cli): align Node 22.12 preflight checks and clean runtime guard output

Tighten installer/runtime consistency so users on Node 22.0-22.11 are blocked before install/runtime drift, with cleaner CLI guidance.

- Enforce Node >=22.12 in scripts/install.sh preflight checks
- Align installer messages to the same 22.12+ runtime floor
- Replace openclaw.mjs thrown version error with stderr+exit to avoid noisy stack traces
This commit is contained in:
Jason Hargrove 2026-03-02 17:55:59 -07:00 committed by Peter Steinberger
parent 96a38d5aa4
commit f8ed48293c
2 changed files with 37 additions and 9 deletions

View File

@ -14,13 +14,14 @@ const ensureSupportedNodeVersion = () => {
return; return;
} }
throw new Error( process.stderr.write(
`openclaw: Node.js v${MIN_NODE_MAJOR}.${MIN_NODE_MINOR}+ is required (current: v${process.versions.node}).\n` + `openclaw: Node.js v${MIN_NODE_MAJOR}.${MIN_NODE_MINOR}+ is required (current: v${process.versions.node}).\n` +
"If you use nvm, run:\n" + "If you use nvm, run:\n" +
" nvm install 22\n" + " nvm install 22\n" +
" nvm use 22\n" + " nvm use 22\n" +
" nvm alias default 22", " nvm alias default 22\n",
); );
process.exit(1);
}; };
ensureSupportedNodeVersion(); ensureSupportedNodeVersion();

View File

@ -1262,6 +1262,35 @@ node_major_version() {
return 1 return 1
} }
node_is_at_least_22_12() {
if ! command -v node &> /dev/null; then
return 1
fi
local version major minor
version="$(node -v 2>/dev/null || true)"
major="${version#v}"
major="${major%%.*}"
minor="${version#v}"
minor="${minor#*.}"
minor="${minor%%.*}"
if [[ ! "$major" =~ ^[0-9]+$ ]]; then
return 1
fi
if [[ ! "$minor" =~ ^[0-9]+$ ]]; then
return 1
fi
if [[ "$major" -gt 22 ]]; then
return 0
fi
if [[ "$major" -eq 22 && "$minor" -ge 12 ]]; then
return 0
fi
return 1
}
print_active_node_paths() { print_active_node_paths() {
if ! command -v node &> /dev/null; then if ! command -v node &> /dev/null; then
return 1 return 1
@ -1314,9 +1343,7 @@ ensure_macos_node22_active() {
} }
ensure_node22_active_shell() { ensure_node22_active_shell() {
local major if node_is_at_least_22_12; then
major="$(node_major_version || true)"
if [[ -n "$major" && "$major" -ge 22 ]]; then
return 0 return 0
fi fi
@ -1324,7 +1351,7 @@ ensure_node22_active_shell() {
active_path="$(command -v node 2>/dev/null || echo "not found")" active_path="$(command -v node 2>/dev/null || echo "not found")"
active_version="$(node -v 2>/dev/null || echo "missing")" active_version="$(node -v 2>/dev/null || echo "missing")"
ui_error "Active Node.js must be v22+ but this shell is using ${active_version} (${active_path})" ui_error "Active Node.js must be v22.12+ but this shell is using ${active_version} (${active_path})"
print_active_node_paths || true print_active_node_paths || true
local nvm_detected=0 local nvm_detected=0
@ -1353,15 +1380,15 @@ ensure_node22_active_shell() {
check_node() { check_node() {
if command -v node &> /dev/null; then if command -v node &> /dev/null; then
NODE_VERSION="$(node_major_version || true)" NODE_VERSION="$(node_major_version || true)"
if [[ -n "$NODE_VERSION" && "$NODE_VERSION" -ge 22 ]]; then if node_is_at_least_22_12; then
ui_success "Node.js v$(node -v | cut -d'v' -f2) found" ui_success "Node.js v$(node -v | cut -d'v' -f2) found"
print_active_node_paths || true print_active_node_paths || true
return 0 return 0
else else
if [[ -n "$NODE_VERSION" ]]; then if [[ -n "$NODE_VERSION" ]]; then
ui_info "Node.js $(node -v) found, upgrading to v22+" ui_info "Node.js $(node -v) found, upgrading to v22.12+"
else else
ui_info "Node.js found but version could not be parsed; reinstalling v22+" ui_info "Node.js found but version could not be parsed; reinstalling v22.12+"
fi fi
return 1 return 1
fi fi