Files
openclaw/openclaw.mjs
Jason Hargrove f8ed48293c 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
2026-03-03 02:03:45 +00:00

81 lines
2.1 KiB
JavaScript
Executable File

#!/usr/bin/env node
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;
}
process.stderr.write(
`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\n",
);
process.exit(1);
};
ensureSupportedNodeVersion();
// https://nodejs.org/api/module.html#module-compile-cache
if (module.enableCompileCache && !process.env.NODE_DISABLE_COMPILE_CACHE) {
try {
module.enableCompileCache();
} catch {
// Ignore errors
}
}
const isModuleNotFoundError = (err) =>
err && typeof err === "object" && "code" in err && err.code === "ERR_MODULE_NOT_FOUND";
const installProcessWarningFilter = async () => {
// Keep bootstrap warnings consistent with the TypeScript runtime.
for (const specifier of ["./dist/warning-filter.js", "./dist/warning-filter.mjs"]) {
try {
const mod = await import(specifier);
if (typeof mod.installProcessWarningFilter === "function") {
mod.installProcessWarningFilter();
return;
}
} catch (err) {
if (isModuleNotFoundError(err)) {
continue;
}
throw err;
}
}
};
await installProcessWarningFilter();
const tryImport = async (specifier) => {
try {
await import(specifier);
return true;
} catch (err) {
// Only swallow missing-module errors; rethrow real runtime errors.
if (isModuleNotFoundError(err)) {
return false;
}
throw err;
}
};
if (await tryImport("./dist/entry.js")) {
// OK
} else if (await tryImport("./dist/entry.mjs")) {
// OK
} else {
throw new Error("openclaw: missing dist/entry.(m)js (build output).");
}