Skip to content

Commit 017b0f9

Browse files
committed
fix(slack-plugin): use namespace imports for CJS/ESM interop
@slack/web-api and @slack/socket-mode are CommonJS modules. Bun's ESM loader cannot resolve named exports (e.g. import { WebClient }) from CJS modules that use Object.defineProperty for export declarations. Namespace imports (import * as X) work because they import the entire module.exports object and destructure at runtime. Signed-off-by: xuezhaojun <xuezhaokeepgoing@gmail.com>
1 parent 9c7936a commit 017b0f9

2 files changed

Lines changed: 11 additions & 4 deletions

File tree

opencode-slack-plugin/package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

opencode-slack-plugin/src/index.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,15 @@
11
// Copyright Contributors to the KubeOpenCode project
22
import type { PluginModule, PluginInput, Hooks } from "@opencode-ai/plugin"
3-
import { SocketModeClient } from "@slack/socket-mode"
4-
import { WebClient } from "@slack/web-api"
3+
// CJS/ESM interop: @slack/web-api and @slack/socket-mode are CommonJS modules.
4+
// Named imports (e.g. import { WebClient }) fail in Bun's ESM loader because
5+
// the exports are defined via Object.defineProperty — not resolvable by static
6+
// analysis. Namespace imports work because they import the entire module.exports
7+
// object and destructure at runtime.
8+
import * as SlackWebApi from "@slack/web-api"
9+
import * as SlackSocketMode from "@slack/socket-mode"
510
import * as os from "os"
11+
const { WebClient } = SlackWebApi
12+
const { SocketModeClient } = SlackSocketMode
613

714
// ---------------------------------------------------------------------------
815
// Types

0 commit comments

Comments
 (0)