Skip to content

Published package fails to load in OpenCode due to broken ESM import specifiers #564

@pandaria75

Description

@pandaria75

Pre-submission checklist

  • I have searched existing issues for duplicates
  • I have reproduced the problem locally
  • I have verified a local fix before opening this issue

Bug description

The published package can fail to load as an OpenCode plugin because the built ESM output contains relative import/export specifiers without explicit .js suffixes.

When that happens, OpenCode does not load the plugin, so requests are not intercepted and routed through the Antigravity OAuth flow. The user-visible symptom is misleading: OpenCode falls back to the default Google provider and reports:

Google Generative AI API key is missing. Pass it using the 'apiKey' parameter or the GOOGLE_GENERATIVE_AI_API_KEY environment variable.

The real problem is that the plugin never loaded.

Reproduction

  1. Build and pack the plugin.
  2. Install the packed package in a clean environment.
  3. Import the package entrypoint or let OpenCode load it as a plugin.
  4. Node/OpenCode fails during ESM resolution before the plugin can initialize.

A representative runtime error is:

Directory import '.../dist/src/plugin' is not supported resolving ES modules imported from .../dist/index.js

There is a second packaging-related problem in the dependency path as well: importing @opencode-ai/plugin from the package root can fail because its root ESM entry re-exports ./tool without an explicit .js suffix.

Root cause

The emitted dist/**/*.js files contain executable relative ESM specifiers that omit the required file extension for Node ESM resolution.

Examples:

export { AntigravityCLIOAuthPlugin, GoogleOAuthPlugin } from "./src/plugin"
export { authorizeAntigravity, exchangeAntigravity } from "./src/antigravity/oauth"

In a packaged consumer environment, those specifiers need to resolve to explicit file targets such as:

export { AntigravityCLIOAuthPlugin, GoogleOAuthPlugin } from "./src/plugin.js"
export { authorizeAntigravity, exchangeAntigravity } from "./src/antigravity/oauth.js"

Verified local fix

I verified a working local fix with two parts:

  1. Run a post-build script that rewrites relative ESM import/export specifiers in dist/**/*.js to explicit .js / /index.js targets.
  2. Import tool from @opencode-ai/plugin/tool instead of @opencode-ai/plugin to avoid the dependency root-entry export problem.

Validation performed

The local fix was validated by:

  • npm run build
  • npm run typecheck
  • npm test
  • direct import('./dist/index.js')
  • npm pack
  • installing the packed tarball into a clean temporary project and importing opencode-antigravity-auth

After the fix, the package entrypoint loads successfully and exports the expected symbols in both the workspace and a clean consumer environment.

Proposed fix

  • Add a build step that normalizes relative ESM specifiers in emitted dist files.
  • Use the explicit @opencode-ai/plugin/tool subpath import in source and tests.

I already have a local patch for this and can open a PR.

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