opencode
opencode copied to clipboard
@opencode-ai/plugin: ESM imports missing .js extension breaks plugin loading
Bug Description
The @opencode-ai/plugin package does not work when installed from npm because:
-
package.jsonexports point to./src/index.tsbut onlydist/is published - The compiled
dist/index.jshasexport * from "./tool"without the.jsextension, which does not resolve in ESM
Steps to Reproduce
- Create a plugin using
@opencode-ai/plugin - Publish it to npm
- Install it in another project
- 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
- Update
package.jsonexports to point to dist:
"exports": {
".": {
"import": "./dist/index.js",
"types": "./dist/index.d.ts"
},
"./tool": {
"import": "./dist/tool.js",
"types": "./dist/tool.d.ts"
}
}
- Add
.jsextensions 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.