Skip to content

upgrade: npm upgrade skips postinstall and leaves an invalid opencode.exe on Windows #55888

Closed as duplicate

Description

@baize-1-heic

Summary

On Windows with a global npm install, opencode upgrade updates @opencode/cli to the new version but does not run the package's postinstall script, so the launcher bin/opencode.exe is left as the 229-byte placeholder. Every subsequent opencode invocation then fails with "is not a valid application for this OS platform" until the user manually runs node postinstall.mjs.

Environment

  • opencode version: upgraded 2.0.29 → 2.0.30 (opencode upgrade)
  • OS: Windows 11, 10.0.26200.9711 (win32 x64)
  • Terminal: TERM=xterm-256color; TERM_PROGRAM and COLORTERM unset
  • Shell: C:\WINDOWS\system32\cmd.exe (commands run through PowerShell 5.1.26100.9711)
  • Install/channel: global npm install (npm i -g @opencode/cli), channel latest
  • npm: 12.0.2, registry is a mirror (registry.npmmirror.com), ignore-scripts config is false
  • Active plugins: none found in config

Reproduction

  1. On Windows, install OpenCode globally with npm: npm i -g @opencode/cli (worked fine at 2.0.29).
  2. Run opencode upgrade. It reports Using method: npm, From 2.0.29 → 2.0.30, then Upgrade complete.
  3. Run opencode --version.

Expected Behavior

opencode --version prints the new version (opencode v2.0.30).

Actual Behavior

The command fails immediately because the launcher is not an executable:

opencode.exe : 无法启动: 指定的可执行文件不是此操作系统平台的有效应用程序
(ApplicationFailedException: The specified executable is not a valid application for this OS platform)
  + CategoryInfo          : ResourceUnavailable: (:) [], ApplicationFailedException
  + FullyQualifiedErrorId : NativeCommandFailed
at C:\Users\<user>\AppData\Roaming\npm\opencode.ps1:14 char:3
+   & "$basedir/node_modules/@opencode/cli/bin/opencode.exe"   $args

%APPDATA%\npm\node_modules\@opencode\cli\bin\opencode.exe is only 229 bytes and contains the placeholder text shipped in the tarball:

echo "Error: @opencode/cli's postinstall script was not run." >&2
echo "" >&2
echo "This occurs when installation scripts are disabled." >&2
echo "Run the package postinstall script or reinstall with scripts enabled." >&2
exit 1

Additional Context

  • The optional platform packages were installed correctly and at the right version, so this is only the missing postinstall hardlink/copy step:
    • @opencode/cli → 2.0.30
    • @opencode/cli-windows-x64 → 2.0.30, bin\opencode.exe = 213,522,824 bytes
    • @opencode/cli-windows-x64-baseline → 2.0.30, bin\opencode.exe = 213,522,824 bytes
  • npm config get ignore-scripts → false, and no ignore-scripts=true in ~/.npmrc or the global npmrc, so scripts were not globally disabled by user config.
  • Workaround that fixed it (no reinstall needed):
    cd "$env:APPDATA\npm\node_modules\@opencode\cli"
    node postinstall.mjs
    After that bin\opencode.exe becomes 213,522,824 bytes and opencode --version prints opencode v2.0.30.
  • Likely cause: the npm upgrade path either installs with lifecycle scripts disabled or extracts the package without running them, and never invokes/repairs the postinstall afterward. The upgrade ends with a success message even though no runnable binary was produced.
  • Impact: on Windows this leaves OpenCode completely unusable after an upgrade until the user knows to run postinstall manually; the failure message points at an OS/executable problem rather than the real cause.
  • Frequency: reproduced on this single 2.0.29 → 2.0.30 upgrade (consistently broken until the manual workaround).

Activity

  1. opencode-agent commented on Oct 15, 2026

    @opencode-agent
    Contributor

    Thanks for the report! Unfortunately the issue body came through as unreadable control characters, but going by the title, I think this is a duplicate of #51553.

    Possible duplicates and related issues, ordered from most to least likely:

    In the meantime, the workarounds reported in #51553 are:

    • run node ./postinstall.mjs in the installed package directory, or
    • reinstall with npm install --global --force --allow-scripts=@opencode/cli @opencode/cli@<version>

    The bot will close this issue as a duplicate in 1 day unless you reply explaining how your problem is different. If it is different, please also include your OpenCode version, npm/Node versions and the exact error you see.

  2. baize-1-heic commented on Oct 15, 2026

    @baize-1-heic
    Author

    Sorry for the noise at the start — the first version of this body was mangled by the tool I used to post it; it has been rewritten above and is now readable.

    Now that the report is readable: this is a duplicate of #51553 (npm 12 upgrade leaves the Windows executable stub), which #51554 is fixing. Closing this one.

    For the record, reproduced on 2.0.30 / npm 12.0.2 / Windows 11: after opencode upgrade the launcher bin\opencode.exe is still the 229-byte stub, while @opencode/cli-windows-x64 and @opencode/cli-windows-x64-baseline are installed at 2.0.30 with a valid 213,522,824-byte bin\opencode.exe. Workaround without reinstalling: cd "$env:APPDATA\npm\node_modules\@opencode\cli"; node postinstall.mjs.

  3. opencode-agent commented on Oct 15, 2026

    @opencode-agent
    Contributor

    Thanks for rewriting the report and for confirming. Your 2.0.30 / npm 12.0.2 / Windows 11 details match #51553: after the upgrade, the launcher bin\opencode.exe is still the stub, while the platform package has the real binary. They're a useful data point on a newer version. Running node postinstall.mjs in the installed @opencode/cli directory is the same workaround reported there.

    Please follow #51553 and PR #51554 for progress. If this issue is still open, the bot will close it as a duplicate.

  4. opencode-agent commented on Oct 16, 2026

    @opencode-agent
    Contributor

    Closing as a duplicate of #51553, as you confirmed. Please follow #51553 and PR #51554 (passes --allow-scripts=@opencode/cli to npm during opencode upgrade) for progress. Until then, running node postinstall.mjs in the installed @opencode/cli directory replaces the stub opencode.exe. Thanks for the clear 2.0.30 reproduction details.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions