opencode icon indicating copy to clipboard operation
opencode copied to clipboard

@opencode-ai/plugin: ESM imports missing .js extension breaks plugin loading

Open derekross opened this issue 3 weeks ago • 1 comments

Bug Description

The @opencode-ai/plugin package does not work when installed from npm because:

  1. package.json exports point to ./src/index.ts but only dist/ is published
  2. The compiled dist/index.js has export * from "./tool" without the .js extension, which does not resolve in ESM

Steps to Reproduce

  1. Create a plugin using @opencode-ai/plugin
  2. Publish it to npm
  3. Install it in another project
  4. Try to load it - fails with "Cannot find module ./tool"

Current Workaround

echo 'export * from "./tool.js";' > node_modules/@opencode-ai/plugin/dist/index.js

Suggested Fix

  1. Update package.json exports to point to dist:
"exports": {
  ".": {
    "import": "./dist/index.js",
    "types": "./dist/index.d.ts"
  },
  "./tool": {
    "import": "./dist/tool.js", 
    "types": "./dist/tool.d.ts"
  }
}
  1. Add .js extensions to source imports:
// src/index.ts
import type { BunShell } from "./shell.js"
import { type ToolDefinition } from "./tool.js"
export * from "./tool.js"

Environment

  • @opencode-ai/plugin version: 1.1.14
  • Node.js version: 22.x
  • OS: Linux

Related

I have a fix ready and will submit a PR.

derekross avatar Jan 12 '26 13:01 derekross

This issue might be related to existing issues with ESM module resolution in OpenCode packages. Please check:

  • #2757: [JS SDK] export field in package.json breaks Vite resolution - Similar package.json export configuration issue
  • #1663: Cannot find module @opencode-ai/sdk@latest when moduleResolution=nodenext - Related ESM module resolution and .js extension requirement
  • #5860: error: Cannot find module '@opencode-ai/plugin' from - Previous report of @opencode-ai/plugin module not found errors
  • #3001: "@opencode-ai/plugin" error when creating custom tools - Custom tool creation failing due to @opencode-ai/plugin not found

Feel free to ignore if none of these address your specific case.

github-actions[bot] avatar Jan 12 '26 13:01 github-actions[bot]