opencode-pty icon indicating copy to clipboard operation
opencode-pty copied to clipboard

[Bug]: `bun:semver` and `bun-pty` imports break plugin loading on OpenCode 1.14.x (Node ESM plugin host)

Open Skeptomenos opened this issue 6 months ago • 4 comments

Summary

[email protected] fails to load on OpenCode 1.14.x (and likely all OpenCode versions since ~1.4.x) because the compiled dist/src/plugin/pty/manager.js imports bun:semver and bun-pty/package.json. OpenCode's plugin host switched from Bun to Node ESM (anomalyco/opencode#18308, merged 2026-04-01), so these Bun-only imports now throw Cannot find package 'bun' at plugin load time.

This is related to but distinct from #7 (Windows + bun-pty GLIBC issue). On macOS the failure happens earlier — the plugin never gets past module resolution because bun:semver isn't a real npm package.

Error in OpenCode log

ERROR 2026-05-05T08:35:35 service=plugin path=opencode-pty@latest
  target=file:///Users/.../.cache/opencode/packages/opencode-pty@latest/node_modules/opencode-pty/dist/index.js
  error=Cannot find package 'bun' imported from
        /Users/.../.cache/opencode/packages/opencode-pty@latest/node_modules/opencode-pty/dist/src/plugin/pty/manager.js
  failed to load plugin

This fires on every workspace bootstrap — for users with multiple projects in the OpenCode sidebar, this means a stack of error toasts + chimes on every cold start.

Reproduction

npm pack [email protected]
tar -xzf opencode-pty-0.3.4.tgz
head -5 package/dist/src/plugin/pty/manager.js
# import { semver } from 'bun';
# import { Terminal } from 'bun-pty';
# import { version as bunPtyVersion } from 'bun-pty/package.json';
# import { NotificationManager } from "./notification-manager.js";
# ...
node -e "import('./package/dist/index.js').catch(e=>console.error(e.message))"
# Cannot find package 'bun' imported from /.../dist/src/plugin/pty/manager.js

Why this is now broken

OpenCode 1.4.x+ replaced the BunProc plugin runtime with @npmcli/arborist + native Node import() (anomalyco/opencode#18308). The Node loader doesn't ship bun:* virtual modules and doesn't have a bun-pty peer package available.

PR #27 ("Ship pre-compiled JS to avoid transpilation cost") helped reduce on-the-fly Bun work but the runtime imports still target Bun's standard library and bun-pty's native .node bindings.

Suggested fix (high-level — likely needs a real refactor)

Replace Bun-specific dependencies with Node-compatible alternatives:

  1. bun:semver → semver (npm). One-line swap.
  2. bun-pty → @lydell/node-pty or the upstream node-pty. OpenCode itself already ships @lydell/node-pty-darwin-arm64 in its app bundle, so the Node ecosystem is the natural target.
  3. Either:
    • Maintain dual support (detect Bun vs Node at runtime and pick the impl), or
    • Drop Bun support and target Node ESM only — which is what OpenCode has effectively already done.

Open question: is there demand to keep Bun-only operation, or can the plugin become Node-first now that OpenCode is Node-based?

Environment

  • OpenCode: 1.14.37 (Electron 41 / Node 24, macOS arm64)
  • Plugin: [email protected] (latest)
  • macOS 26.4.1 arm64
  • Plugin declared globally in ~/.config/opencode/opencode.json "plugin" array; fails on every workspace bootstrap.

References

  • Related: shekohex/opencode-pty#7 (Windows startup crash, also bun-pty-driven)
  • Upstream loader change: anomalyco/opencode#18308 ("refactor: replace BunProc with Npm module using @npmcli/arborist")
  • Related upstream issues mentioning Bun-only plugins breaking: anomalyco/opencode#22045, anomalyco/opencode#13282

Skeptomenos avatar May 05 '26 09:05 Skeptomenos

workaround for now

bun --bun `which opencode`

eslym avatar May 05 '26 13:05 eslym

Same bug on Windows 11 + OpenCode Desktop 1.18.15 (latest production). Confirming this is not just a Linux/macOS issue:

  • Installed @josxa/[email protected] (the actively maintained fork) in global config via "plugin": ["@josxa/opencode-pty"].
  • The plugin fails silently — no pty_* tools, no /pty-* slash commands, no error toast. Desktop sidecar is Node-based and bun-pty requires bun >= 1.0.0 (engines), so the plugin never instantiates.
  • Verified with npm view bun-pty engines → { bun: '>=1.0.0' }.

This is the same class of breakage as anomalyco/opencode#41033 (Desktop V2 Bun sidecar not bundled yet). If a Node-compatible fallback (e.g. node-pty) or a runtime detection + clear startup warning were added, Desktop users would at least get a diagnostic instead of a silent drop.

Environment:

  • OS: Windows 11 x64
  • OpenCode Desktop: 1.18.15
  • Plugin: @josxa/opencode-pty 0.7.3 (fork of this repo)

Cross-link with anomalyco/opencode #6635 and #41033 — same Node-ESM-vs-Bun plugin-host incompatibility. This is the canonical "plugin only works on Bun" case. A documented plugin-host compatibility note (and the GUI in #41037 to surface failures) would resolve a lot of user confusion.

Confirming this on OpenCode Desktop 1.18.32 (Electron 42.3.3, bundled Node 24.15.0) with opencode-pty 0.4.0.

Plugin load fails with:

Stripping types is currently unsupported for files under node_modules,
for ".../node_modules/bun-pty/src/index.ts"

Both the default entry and opencode-pty/v2 are affected — the import chain reaches bun-pty in both cases. Minimal reproduction:

# Electron/Node (desktop runtime)
ELECTRON_RUN_AS_NODE=1 electron --input-type=module \
  -e "import('<cache>/packages/opencode-pty/node_modules/opencode-pty/dist/index.js')"
# -> Stripping types is currently unsupported ... bun-pty/src/index.ts

# Bun (CLI runtime)
bun -e "import('<...>/opencode-pty/dist/index.js')"
# -> OK

Impact: pty_* tools are unavailable in every OpenCode Desktop session; only CLI/TUI users can use the plugin. A runtime-neutral PTY (e.g. node-pty with prebuilt artifacts) or shipping bun-pty prebuilt (no TS in node_modules) would fix it.

Randylinux avatar Sep 24 '26 20:09 Randylinux