fix: add .js extensions to relative imports so the plugin loads under ESM#15
Open
Robespierred0p wants to merge 2 commits into
Open
fix: add .js extensions to relative imports so the plugin loads under ESM#15Robespierred0p wants to merge 2 commits into
Robespierred0p wants to merge 2 commits into
Conversation
… ESM The compiled dist/index.js used extensionless relative imports (e.g. "./src/push/formatter") because tsconfig uses moduleResolution "bundler". OpenCode's strict ESM plugin loader requires explicit extensions and throws "Cannot find module", so the plugin failed to load entirely. Add .js to all relative imports in the plugin runtime graph (index.ts, src/push/*, src/tunnel/*, src/utils, src/proxy). The src/cli/* files already used .js. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
On OpenCode 1.14.33, the published
opencode-mobileplugin fails to load and never starts a tunnel. The OpenCode log shows:This is why users see
No tunnel URL foundfrom/mobile— the plugin never actually loads.Root cause
tsconfig.jsonuses"moduleResolution": "bundler", which allows the source to omit file extensions on relative imports and emits them unchanged (e.g.import { formatNotification } from "./src/push/formatter"). OpenCode loads plugins with strict ESM resolution, which requires explicit.jsextensions, so every extensionless relative specifier throwsERR_MODULE_NOT_FOUNDand the whole plugin fails to load.dist/src/push/formatter.jsexists in the published package — it just can't be resolved without the extension.The
src/cli/*files already use.jsextensions; only the plugin runtime graph (reachable fromindex.ts) was affected.Fix
Add
.jsextensions to all relative imports in the plugin runtime graph:index.tssrc/push/{index,formatter,sender,token-store}.tssrc/tunnel/{index,cloudflare,localtunnel,ngrok}.tssrc/utils/index.tssrc/proxy/index.ts11 files, 30 lines. No behavior changes — only import specifiers.
Verification
After
npm run build, loaded the built plugin into OpenCode 1.14.33 via the local plugins dir. The plugin now initializes cleanly (no module error), the serve-mode gate passes, the Cloudflare tunnel starts, and the QR/URL are generated:Suggested follow-up (not in this PR)
Consider switching
tsconfig.jsonto"moduleResolution": "nodenext"so extensionless relative imports become compile-time errors and this class of bug can't regress.🤖 Generated with Claude Code