[PR #13544] fix: skip non-function exports when loading external plugins #14713

Open
opened 2026-02-16 18:19:29 -05:00 by yindo · 0 comments
Owner

Original Pull Request: https://github.com/anomalyco/opencode/pull/13544

State: open
Merged: No


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

**Original Pull Request:** https://github.com/anomalyco/opencode/pull/13544 **State:** open **Merged:** No --- ## 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
yindo added the pull-request label 2026-02-16 18:19:29 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: anomalyco/opencode#14713