Skip to content

Commit 3cc34ea

Browse files
committed
fix: bundle @slack SDK into plugin to avoid CJS/ESM interop issues
Bun's runtime cannot resolve named exports from CJS modules that use Object.defineProperty getters (e.g. @slack/web-api's WebClient). Static imports, namespace imports, createRequire, and dynamic import() all fail because Bun strips getter-defined properties from the ESM namespace object. The only reliable solution is to avoid runtime CJS/ESM interop entirely by bundling the @slack/* packages into the plugin with tsup. This eliminates the dependency on Bun correctly handling CJS module namespaces. Signed-off-by: xuezhaojun <xuezhaokeepgoing@gmail.com>
1 parent 21af755 commit 3cc34ea

3 files changed

Lines changed: 8 additions & 18 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/package.json

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@kubeopencode/opencode-slack-plugin",
3-
"version": "0.1.4",
3+
"version": "0.1.6",
44
"type": "module",
55
"license": "MIT",
66
"description": "OpenCode plugin that connects to Slack via Socket Mode — zero port exposure, runs inside your OpenCode process",
@@ -34,12 +34,11 @@
3434
"typecheck": "tsc --noEmit",
3535
"dev": "tsup src/index.ts --format esm --dts --watch"
3636
},
37-
"dependencies": {
38-
"@slack/socket-mode": "^2.0.5",
39-
"@slack/web-api": "^7.13.0"
40-
},
37+
"dependencies": {},
4138
"devDependencies": {
4239
"@opencode-ai/plugin": "^1.2.15",
40+
"@slack/socket-mode": "^2.0.5",
41+
"@slack/web-api": "^7.13.0",
4342
"@types/node": "^22.0.0",
4443
"tsup": "^8.5.0",
4544
"typescript": "^5.9.0"

opencode-slack-plugin/src/index.ts

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,8 @@
11
// Copyright Contributors to the KubeOpenCode project
22
import type { PluginModule, PluginInput, Hooks } from "@opencode-ai/plugin"
3+
import { WebClient } from "@slack/web-api"
4+
import { SocketModeClient } from "@slack/socket-mode"
35
import * as os from "os"
4-
// CJS/ESM interop: @slack/web-api and @slack/socket-mode are CJS modules that
5-
// use Object.defineProperty for their exports. Bun's bundler cannot resolve
6-
// named imports (produces "X is not a constructor"), namespace imports lose
7-
// getter-defined properties in the bundled namespace, and require() is blocked
8-
// by Bun for async CJS modules. Dynamic import() forces Bun to handle the
9-
// interop at runtime, preserving all exports including constructors.
10-
const slackWebApi = await import("@slack/web-api") as typeof import("@slack/web-api")
11-
const slackSocketMode = await import("@slack/socket-mode") as typeof import("@slack/socket-mode")
12-
const { WebClient } = slackWebApi
13-
const { SocketModeClient } = slackSocketMode
146

157
// ---------------------------------------------------------------------------
168
// Types
@@ -219,7 +211,6 @@ const slack = async (input: PluginInput): Promise<Hooks> => {
219211
const appToken = process.env.SLACK_APP_TOKEN
220212

221213
if (!botToken || !appToken) {
222-
// Not configured — silently skip.
223214
return {}
224215
}
225216

0 commit comments

Comments
 (0)