Skip to content

[Bug]: main: ./index.ts is not loadable under OpenCode 1.14.x's Node ESM plugin host — needs a compiled dist/ #74

@Skeptomenos

Description

@Skeptomenos

Summary

opencode-gemini-auth@1.4.12 (and earlier) ships only TypeScript source (index.ts, src/*.ts) and points main and module at ./index.ts. Under Bun this transpiled on the fly, but since OpenCode 1.14.x switched its plugin host to strict Node ESM (anomalyco/opencode#18308, merged 2026-04-01), the loader cannot resolve index.ts and falls back to a directory import — which Node ESM rejects.

Issue #70 attempted to fix this by adding "main": "./index.ts" in 1.4.10, but pointing main at a .ts file does not solve the underlying problem: OpenCode's loader is now Node-based and does not transpile TypeScript. The plugin needs a compiled dist/index.js (or equivalent exports map pointing at compiled JS) to load.

Error in OpenCode log

ERROR 2026-05-05T08:35:36 service=plugin path=opencode-gemini-auth@1.4.9
  target=/Users/.../.cache/opencode/packages/opencode-gemini-auth@1.4.9/node_modules/opencode-gemini-auth
  error=Directory import '/Users/.../.cache/opencode/packages/opencode-gemini-auth@1.4.9/node_modules/opencode-gemini-auth'
        is not supported resolving ES modules imported from
        /Applications/OpenCode.app/Contents/Resources/app.asar/out/main/chunks/node-8ljIuRcm.js
  failed to load plugin

(Identical failure on 1.4.10, 1.4.11, 1.4.12 — all ship the same source-only layout.)

Reproduction

npm pack opencode-gemini-auth@1.4.12
tar -xzf opencode-gemini-auth-1.4.12.tgz
ls package/
# LICENSE  README.md  index.ts  package.json  src
# (no dist/, no compiled JS)

cat package/package.json | grep -E '"main"|"module"|"type"'
#   "main": "./index.ts",
#   "module": "index.ts",
#   "type": "module",

node -e "import('./package/index.ts').then(()=>console.log('ok')).catch(e=>console.error(e.message))"
# Unknown file extension ".ts" for /.../package/index.ts

When OpenCode's loader (Node 24 / Electron 41) is given a target directory node_modules/opencode-gemini-auth, the only entry it can see is index.ts. Node ESM doesn't load .ts, so it tries to import the directory itself as a module — and fails with "Directory import ... is not supported".

Why this is now broken

Suggested fix

  1. Add a build step that emits dist/index.js (e.g. tsup, tsc, or bun build --target=node).
  2. Update package.json:
    {
      "main": "./dist/index.js",
      "types": "./dist/index.d.ts",
      "exports": {
        ".": { "import": "./dist/index.js", "types": "./dist/index.d.ts" },
        "./server": { "import": "./dist/index.js", "types": "./dist/index.d.ts" }
      },
      "files": ["dist", "README.md", "LICENSE"]
    }
  3. Add a prepublishOnly smoke test that does node -e "import(require.resolve('opencode-gemini-auth'))" to catch regressions.

For prior art, see the tsup setup in @tarquinen/opencode-dcp PR #499: Opencode-DCP/opencode-dynamic-context-pruning#499

Environment

  • OpenCode: 1.14.37 (Electron 41 / Node 24, macOS arm64)
  • Plugin: opencode-gemini-auth@1.4.9 (also reproduced against 1.4.10, 1.4.11, 1.4.12)
  • macOS 26.4.1 arm64
  • Plugin declared in a project-level opencode.json "plugin" array; fails on every workspace bootstrap.

References

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions