cli: manual recovery `node postinstall.mjs` fails on Windows - `npm_execpath` unset causes silent `spawnSync("npm")` ENOENT
I maintainer di solito rispondono entro 1 giorno
Valutazione
- Difficoltà
- 2/5
- Tempo stimato
- 1-3 ore
- Idoneità per principianti
- 73/100
- Tipo di issue
- Bug
- Chiarezza
- Specificata chiaramente
- Stato di attività
- Attiva
- Stack tecnologico
- node.js, typescript
- Ambito
- build-system, cli
Direzione di ricerca
Inizia da packages/cli/postinstall.mjs, in particolare dalla selezione dell’eseguibile npm e dalla gestione di installPackage() descritte nel report. Riproduci il problema eseguendo node postinstall.mjs al di fuori di un ciclo di vita npm su Windows e controlla il risultato di spawn. Il lavoro è completato quando il ripristino manuale riesce a invocare npm e gli errori espongono l’errore sottostante.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
Summary
The manual recovery step recommended in #55888 - running node postinstall.mjs inside the installed @opencode/cli package - cannot work on Windows when invoked outside an npm lifecycle context.
postinstall.mjs only resolves the npm CLI correctly when npm_execpath is set. Otherwise it falls back to spawnSync("npm", ...), which always fails with ENOENT on Windows because the npm shim is npm.cmd.
The failure is silent: installPackage() treats a non-zero status as a failed install and continues, so the user only ever sees the generic Failed to install OpenCode. Try manually installing ... message, with no npm output and no hint of the real cause.
Environment
- opencode version: 2.0.31
- OS: Windows 11 (win32 x64)
- Node: v24.18.0
- npm: 11.16.0
- Install method: global npm install (
npm i -g @opencode/cli) npm_execpath: unset (becausepostinstall.mjswas run directly withnode)
Root cause
packages/cli/postinstall.mjs:
// Windows cannot spawn npm's .cmd shim directly, so reuse the npm CLI that runs this script.
const npm = process.env.npm_execpath?.endsWith("npm-cli.js")
? [process.execPath, process.env.npm_execpath]
: ["npm"]
The comment states the intent, but the ["npm"] fallback is unreachable on Windows. childProcess.spawnSync("npm", ...) without shell: true does not resolve .cmd shims through PATHEXT.
Reproduction
PS> cd $env:APPDATA\npm\node_modules\@opencode\cli
PS> node postinstall.mjs
Failed to install OpenCode. Try manually installing "@opencode/cli-windows-x64" or "@opencode/cli-windows-x64-baseline".
# exit code 1, ~0.4s, no npm output
Evidence
Same machine, same session:
npm_execpath = undefined
spawnSync("npm", ...) -> status = null error = ENOENT
spawnSync("npm.cmd", ...) -> status = null error = EINVAL
spawnSync(process.execPath, [npmCliJs, "--version"]) -> status = 0 stdout = "11.16.0"
Setting npm_execpath makes the identical invocation succeed:
PS> $env:npm_execpath = "C:\Program Files\nodejs\node_modules\npm\bin\npm-cli.js"
PS> node postinstall.mjs
# exit code 0
Suggested fix
Resolve the npm CLI robustly instead of assuming it is directly spawnable:
- resolve
npm-cli.jsrelative toprocess.execPath(../node_modules/npm/bin/npm-cli.js), or - fall back to
npm.cmdwithshell: true, or - resolve through
PATHEXT
Separately, consider surfacing result.error when installPackage fails - the current message hides ENOENT entirely, which makes this hard to diagnose.
Additional context
This machine was in the state described by #55888 (bin/opencode.exe left as the 229-byte placeholder). Because node postinstall.mjs was the suggested recovery and it fails on Windows, the install could not be repaired without manually setting npm_execpath.
Related
- #55888 (closed) - recommends
node postinstall.mjsas manual recovery - #51553 (open) - npm 12 upgrade leaves the Windows executable stub
- Lingua principale
- TypeScript
- Stelle
- 215k
- Fork
- 28.9k
- Merge medio
- 11h 19m
- PR unite (30g)
- 320
Preparare l'ambiente
- Nessun Dockerfile né file Docker Compose
- Ha un modello di pull request
- Leggi la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di anomalyco/opencode
-
pending close triaging
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
anomalyco/opencode#57209 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno
-
reproduced
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
anomalyco/opencode#57127 · 2 commenti ·
I maintainer di solito rispondono entro 1 giorno
-
pending close triaging
Difficoltà 2/5 1-3 ore Idoneità per principianti 66/100
anomalyco/opencode#57070 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno
-
Plan mode leave reminder becomes the final user turn after a tool-driven agent switch, models refuseForse già presa @Veld101 l’ha presa 1 giorno fa. Apertareproduced
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
anomalyco/opencode#57013 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 64/100
anomalyco/opencode#56891 · 2 commenti ·
I maintainer di solito rispondono entro 1 giorno
Tutte le issue di anomalyco/opencode
Issue simili
-
engine-rs P3 review-deferral wasm
Difficoltà 2/5 1-3 ore Idoneità per principianti 77/100
maniator/verticopolis#1154 ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 85/100
I maintainer di solito rispondono entro 1 giorno
-
Bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 76/100
telerik/kendo-react#3861 ·
I maintainer di solito rispondono entro 1 giorno
-
[bug]: use-mobile.ts uses pixel logic, causing UI state de-sync with Tailwind CSS rem breakpointsApertabug
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
I maintainer di solito rispondono entro 1 giorno
-
task
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100