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

Open
opened 2026-02-16 17:46:28 -05:00 by yindo · 0 comments
Owner

Originally created by @derekross on GitHub (Jan 12, 2026).

Originally assigned to: @thdxr on GitHub.

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.

Originally created by @derekross on GitHub (Jan 12, 2026). Originally assigned to: @thdxr on GitHub. ## 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 ```bash echo 'export * from "./tool.js";' > node_modules/@opencode-ai/plugin/dist/index.js ``` ## Suggested Fix 1. Update `package.json` exports to point to dist: ```json "exports": { ".": { "import": "./dist/index.js", "types": "./dist/index.d.ts" }, "./tool": { "import": "./dist/tool.js", "types": "./dist/tool.d.ts" } } ``` 2. Add `.js` extensions to source imports: ```ts // 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.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: anomalyco/opencode#4913