PS W:\JavaWeb_code\RollCallSystem> codex
file:///W:/NVM/nvm/v24.12.0/node_modules/@openai/codex/bin/codex.js:100
    throw new Error(
          ^

Error: Missing optional dependency @openai/codex-win32-x64. Reinstall Codex: npm install -g @openai/codex@latest
    at file:///W:/NVM/nvm/v24.12.0/node_modules/@openai/codex/bin/codex.js:100:11
    at ModuleJob.run (node:internal/modules/esm/module_job:413:25)
    at async onImport.tracePromise.__proto__ (node:internal/modules/esm/loader:660:26)
    at async asyncRunEntryPointWithESMLoader (node:internal/modules/run_main:101:5)

Node.js v24.12.0

今天突然发现运行 Codex 出现了报错,起初以为是缺少了什么包,问了 Gemini,他建议我手动重新安装,结果无效

随后在 Github 上找到了解决方法,大概是原理是:npm view 去远程仓库查询 @openai/codex 当前最新的版本号(例如 0.105.0),并将其存储在变量 $v 中,然后安装指定版本的包 。

$v = npm view @openai/codex version
npm install -g "@openai/codex@$v" "@openai/codex-win32-x64@npm:@openai/codex@$v-win32-x64"

这个方法最终也失败了,显示Codex官方没有发布这个版本的包,但是事实上 Github 上最新版本就是 0.120.0

PS C:\Users\DING> $v = npm view @openai/codex version
PS C:\Users\DING> npm install -g "@openai/codex@$v" "@openai/codex-win32-x64@npm:@openai/codex@$v-win32-x64"
npm error code ETARGET
npm error notarget No matching version found for @openai/codex@0.120.0-win32-x64.
npm error notarget In most cases you or one of your dependencies are requesting
npm error notarget a package version that doesn't exist.
npm error A complete log of this run can be found in: C:\Users\DING\AppData\Local\npm-cache\_logs\2026-04-11T09_41_34_980Z-debug-0.log

最终我通过安装上一版本的 Codex CLI(0.119.0),暂时修复了这个 bug,等待官方优化

npm install -g "@openai/codex-win32-x64@npm:@openai/codex@0.119.0-win32-x64"
Logo

欢迎加入DeepSeek 技术社区。在这里,你可以找到志同道合的朋友,共同探索AI技术的奥秘。

更多推荐