Skip to content

Commit 21af755

Browse files
committed
fix: use dynamic import() for CJS @slack packages
Bun blocks require() for async CJS modules. Dynamic import() forces runtime resolution which correctly preserves Object.defineProperty exports like WebClient and SocketModeClient. Signed-off-by: xuezhaojun <xuezhaokeepgoing@gmail.com>
1 parent b54120c commit 21af755

3 files changed

Lines changed: 13 additions & 13 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: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@kubeopencode/opencode-slack-plugin",
3-
"version": "0.1.3",
3+
"version": "0.1.4",
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",

opencode-slack-plugin/src/index.ts

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
// Copyright Contributors to the KubeOpenCode project
22
import type { PluginModule, PluginInput, Hooks } from "@opencode-ai/plugin"
3-
import { createRequire } from "node:module"
43
import * as os from "os"
5-
// CJS/ESM interop: @slack/web-api and @slack/socket-mode are CommonJS modules
6-
// that use Object.defineProperty for their exports. Bun's bundler cannot
7-
// resolve named imports from these (it produces "X is not a constructor" at
8-
// runtime). Namespace imports (import * as) also fail because Bun's bundled
9-
// namespace object loses the getter-defined properties. Using createRequire to
10-
// load them as CJS guarantees the real module.exports with all constructors.
11-
const require = createRequire(import.meta.url)
12-
const { WebClient } = require("@slack/web-api") as typeof import("@slack/web-api")
13-
const { SocketModeClient } = require("@slack/socket-mode") as typeof import("@slack/socket-mode")
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
1414

1515
// ---------------------------------------------------------------------------
1616
// Types

0 commit comments

Comments
 (0)