Skip to content

TypeError: fn3 is not a function in plugin hook execution (src/plugin/index.ts:87) #11392

@Puri12

Description

@Puri12

Bug Report

Environment

  • OpenCode version: latest
  • Plugin: opencode-discord-presence v0.2.7
  • @opencode-ai/plugin: v1.1.44

Error Message

[discord-rpc] Connected to Discord
{
  "name": "UnknownError",
  "data": {
    "message": "TypeError: fn3 is not a function. (In 'fn3(input)', 'fn3' is an instance of Array)\n    at <anonymous> (src/plugin/index.ts:87:28)\n    at processTicksAndRejections (native:7:39)"
  }
}

Description

When using a plugin that exports hooks (chat.message, event), OpenCode's internal plugin system throws an error at src/plugin/index.ts:87:28 stating that fn3 is not a function and that it's actually an Array.

Plugin Code (simplified)

import type { Plugin } from "@opencode-ai/plugin"

export const OpenCodeDiscordPresence: Plugin = async (ctx) => {
  // ... setup code ...
  
  return {
    "chat.message": async (input) => {
      // handle message
    },
    event: async ({ event }) => {
      // handle event
    },
  }
}

export default OpenCodeDiscordPresence

Expected Behavior

The plugin hooks should be called correctly without type errors.

Actual Behavior

OpenCode's plugin system fails to execute the hooks, treating them as arrays instead of functions.

Possible Cause

Looking at the @opencode-ai/plugin type definitions, the chat.message hook signature is:

"chat.message"?: (input: {...}, output: {...}) => Promise<void>;

This takes TWO parameters (input and output), but the error suggests there may be an internal issue with how hooks are being collected or called within OpenCode's plugin orchestration layer at src/plugin/index.ts:87.

Additional Context

  • The Discord RPC connection succeeds (as shown by the log)
  • The error occurs during hook execution, not plugin initialization
  • Stack trace points to src/plugin/index.ts:87:28 in OpenCode's source
  • The plugin is exported correctly as both named and default export

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions