Skip to content

fix: skip non-function exports when loading external plugins#13544

Closed
intergrado-cg wants to merge 1 commit into
anomalyco:devfrom
intergrado-cg:dev
Closed

fix: skip non-function exports when loading external plugins#13544
intergrado-cg wants to merge 1 commit into
anomalyco:devfrom
intergrado-cg:dev

Conversation

@intergrado-cg

Copy link
Copy Markdown

Summary

External plugins fail to load with TypeError: fn is not a function because the plugin loading code iterates over ALL exports from a module and tries to call each as a Plugin function. External plugins typically export many things besides the Plugin function (helpers, constants, types), causing the error when non-function exports are encountered.

Root Cause

In packages/opencode/src/plugin/index.ts, the plugin loading loop iterates over all exports using Object.entries(mod) and attempts to call each as a Plugin function without checking if the export is actually a function.

Fix

Add a typeof fn !== "function" check before attempting to call the export as a Plugin function.

Changes

  • packages/opencode/src/plugin/index.ts: Added type check to skip non-function exports

Testing

Created a test plugin that exports additional non-function values (SOME_CONSTANT, someObject) alongside the Plugin function. Verified the plugin now loads successfully.

Related Issue

Fixes #13543

External plugins typically export many things besides the Plugin function
(helpers, constants, types). The plugin loading code iterates over ALL
exports from a module and tries to call each as a Plugin function, which
causes a TypeError when non-functions are encountered.

This fix adds a typeof check to skip non-function exports.
@github-actions

Copy link
Copy Markdown
Contributor

Closing this pull request because it has had no updates for more than 60 days. If you plan to continue working on it, feel free to reopen or open a new PR.

@github-actions github-actions Bot closed this Apr 15, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

External plugins fail to load: TypeError: fn is not a function

1 participant