fix(cli): fail fast on unsupported Node versions in install and runtime paths

Surface a clear Node 22.12+ requirement before npm/install bootstrap work so users avoid misleading downstream errors.

- Add installer shell preflight to block active Node <22 and suggest NVM recovery commands
- Add openclaw.mjs runtime preflight for npm/npx usage with explicit Node version guidance
- Keep messaging actionable for both NVM and non-NVM environments
This commit is contained in:
Jason Hargrove
2026-03-02 17:16:31 -07:00
committed by Peter Steinberger
parent c7ec237089
commit 96a38d5aa4
2 changed files with 63 additions and 0 deletions

View File

@@ -2,6 +2,29 @@
import module from "node:module";
const MIN_NODE_MAJOR = 22;
const MIN_NODE_MINOR = 12;
const ensureSupportedNodeVersion = () => {
const [majorRaw = "0", minorRaw = "0"] = process.versions.node.split(".");
const major = Number(majorRaw);
const minor = Number(minorRaw);
const supported = major > MIN_NODE_MAJOR || (major === MIN_NODE_MAJOR && minor >= MIN_NODE_MINOR);
if (supported) {
return;
}
throw new Error(
`openclaw: Node.js v${MIN_NODE_MAJOR}.${MIN_NODE_MINOR}+ is required (current: v${process.versions.node}).\n` +
"If you use nvm, run:\n" +
" nvm install 22\n" +
" nvm use 22\n" +
" nvm alias default 22",
);
};
ensureSupportedNodeVersion();
// https://nodejs.org/api/module.html#module-compile-cache
if (module.enableCompileCache && !process.env.NODE_DISABLE_COMPILE_CACHE) {
try {