From 14b0a97ba2d1b0d0a1a595cd5a16097be8c7bf6c Mon Sep 17 00:00:00 2001 From: owenchak-oai Date: Mon, 2 Jun 2025 19:55:57 -0700 Subject: [PATCH] Derive required Node version from package.json --- codex-cli/bin/codex.js | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/codex-cli/bin/codex.js b/codex-cli/bin/codex.js index 1bfb9f5d5d..4023f4436c 100755 --- a/codex-cli/bin/codex.js +++ b/codex-cli/bin/codex.js @@ -81,6 +81,18 @@ if (wantsNative) { process.exit(exitCode); } +// Ensure a compatible Node version before falling back to the JavaScript CLI. +const pkgJsonPath = path.join(__dirname, "../package.json"); +const { engines } = JSON.parse(fs.readFileSync(pkgJsonPath, "utf8")); +const requiredNodeMajor = Number.parseInt(engines.node.match(/\d+/)[0], 10); +const currentMajor = Number.parseInt(process.versions.node.split(".")[0], 10); +if (currentMajor < requiredNodeMajor) { + console.error( + `Codex CLI requires Node.js ${requiredNodeMajor} or newer. Detected ${process.version}. Please upgrade your Node.js installation.` + ); + process.exit(1); +} + // Fallback: execute the original JavaScript CLI. // Resolve the path to the compiled CLI bundle