Skip to content

Plugin loader throws TypeError or executes arbitrary named utility exports in legacy plugins #50021

Closed as not planned

Description

@rapha4lx

Description

In packages/opencode/src/plugin/index.ts, getLegacyPlugins iterates over all exported values of a plugin module (Object.values(mod)):

for (const entry of Object.values(mod)) {
  if (seen.has(entry)) continue
  seen.add(entry)
  const plugin = getServerPlugin(entry)
  if (!plugin) throw new TypeError("Plugin export is not a function")
  result.push(plugin)
}

This causes two issues when authoring plugins:

  1. If a plugin file contains export default async function(ctx) { ... } alongside non-function exports (e.g. export const config = { ... } or constants), getServerPlugin returns undefined for non-functions and it throws TypeError: Plugin export is not a function, failing plugin load.
  2. If a plugin exports helper functions (e.g. for unit testing), OpenCode treats every exported function as a plugin initializer and invokes it with (input, load.options), causing unexpected calls or exceptions when the helper expects different arguments.

OpenCode version

1.18.31

Steps to reproduce

  1. Create a plugin file exporting both a default plugin function and a constant:
export const MY_CONFIG = { foo: "bar" }
export default async function(ctx) {
  return {}
}
  1. Run opencode.
  2. Loading fails with TypeError: Plugin export is not a function.

Operating System

Linux

Activity

  1. thdxr commented on Oct 11, 2026

    @thdxr
    Member

    Thanks for the report! OpenCode 2.0 is now out and development is focused on V2, so we're closing issues filed against OpenCode 1. Please upgrade (opencode upgrade --major, details: https://anoma.ly/notes/opencode-2-0), and if this is still relevant on 2.0, reopen this issue or open a new one with your 2.0 version.

    — from 𝕺𝖕𝖊𝖓𝕮𝖔𝖉𝖊

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions