Skip to content

🐛 Bug: Channels can't run on Cloudflare Workers: channels-core calls createRequire at load, and channels-intelligence is imported by a variable specifier #8539

Description

@Laptopmini

♻️ Reproduction Steps

Follow-up to #6919. Its closing comment says the createRequire(import.meta.url) in @copilotkit/channels-core "is not in the Worker bundle" because no v2 runtime entry reaches it. That holds for the runtime on its own. A Worker that hosts a Channel does reach it, and then hits a second problem when the runtime activates the Channel through Intelligence.

Script (local workerd through wrangler dev, no Cloudflare account needed):

mkdir cpk-channels-worker && cd cpk-channels-worker
npm init -y > /dev/null
npm i --no-audit --no-fund @copilotkit/[email protected] @copilotkit/[email protected] @copilotkit/[email protected] @ag-ui/client [email protected] > /dev/null
mkdir src
cat > src/core.ts <<'EOF'
import { createChannel } from "@copilotkit/channels-core";
export default { fetch: () => new Response(typeof createChannel) };
EOF
cat > src/managed.ts <<'EOF'
import { CopilotKitIntelligence, CopilotRuntime, createCopilotRuntimeHandler } from "@copilotkit/runtime/v2";
import { createChannel } from "@copilotkit/channels-core";
import { HttpAgent } from "@ag-ui/client";
export default {
  async fetch() {
    const channel = createChannel({
      name: "repro",
      identifyUser: "platform",
      adapters: [],
      agent: (threadId: string) => new HttpAgent({ url: "http://127.0.0.1:9/agent", threadId }),
    } as any);
    const runtime = new CopilotRuntime({
      // Dead local address: this only exercises activation, no account needed.
      intelligence: new CopilotKitIntelligence({ apiKey: "cpk-1_notarealkey", apiUrl: "http://127.0.0.1:9/api", wsUrl: "ws://127.0.0.1:9/socket" }),
      agents: () => ({ default: new HttpAgent({ url: "http://127.0.0.1:9/agent" }) }),
      identifyUser: () => ({ id: "u", name: "U" }),
      channels: [channel],
    } as any);
    const handler: any = createCopilotRuntimeHandler({ runtime, basePath: "/api" });
    const timeout = new Promise((r) => setTimeout(() => r("ready() still pending after 3s"), 3000));
    const result = await Promise.race([handler.channels.ready().then(() => "ready"), timeout]).catch((e: Error) => "ready failed: " + e.message);
    return new Response(String(result));
  },
};
EOF
printf 'name = "core"\nmain = "src/core.ts"\ncompatibility_date = "2026-11-01"\ncompatibility_flags = ["nodejs_compat"]\n[vars]\nCOPILOTKIT_TELEMETRY_DISABLED = "true"\n' > core.toml
sed 's/"core"/"managed"/; s#src/core.ts#src/managed.ts#' core.toml > managed.toml
  1. npx wrangler dev -c core.toml. The Worker doesn't start (log below). That's const pkg = createRequire(import.meta.url)("../package.json") at the top of channels-core/dist/create-channel.js (source: packages/channels-core/src/create-channel.ts:70-72). workerd leaves import.meta.url undefined, so the call throws while the module loads. pkg is only used for telemetry (packageName/packageVersion).
  2. Replace that line with a literal to get past it (macOS sed; on Linux drop the ''):
    sed -i '' 's#^const pkg = createRequire(import.meta.url)("../package.json");#const pkg = { name: "@copilotkit/channels-core", version: "0.12.0" };#' node_modules/@copilotkit/channels-core/dist/create-channel.js
    npx wrangler dev -c core.toml, then curl localhost:8787/ prints function. (In a fuller probe, with an in-memory adapter and a fake agent, a Channel on its own runner then runs a turn end to end on workerd.)
  3. npx wrangler dev -c managed.toml, then curl localhost:8787/ prints ready failed: ChannelManager.ready: 1 channel(s) failed to activate or settle in time, and the log shows Error: No such module "@copilotkit/channels-intelligence". defaultActivateChannel loads the package with import(CHANNELS_INTELLIGENCE_SPECIFIER) (packages/runtime/src/v2/runtime/core/channel-manager.ts:389,481). A bundler can't follow a variable specifier, so the package never makes it into the Worker bundle, even though it's installed. The error also skips the friendly "Managed Channels require '@copilotkit/channels-intelligence' to be installed" message, because isModuleNotFound only checks ERR_MODULE_NOT_FOUND / MODULE_NOT_FOUND, and workerd throws a plain Error without a code.
  4. If I also change that line in dist/v2/runtime/core/channel-manager.mjs to a literal, the error goes away and curl prints ready() still pending after 3s:
    sed -i '' 's#() => import(CHANNELS_INTELLIGENCE_SPECIFIER)#() => import("@copilotkit/channels-intelligence")#' node_modules/@copilotkit/runtime/dist/v2/runtime/core/channel-manager.mjs
    With a WebSocket spy in the same Worker, I can see activation open ws://127.0.0.1:9/socket/channels/websocket?vsn=2.0.0 through the global WebSocket and keep retrying (the address is dead on purpose). I haven't tried this against a live Intelligence project.

Same results with compatibility_flags = [], and on the next line (@copilotkit/[email protected], channels-core / channels-intelligence 0.13.0-rc.15). Both lines are unchanged on main (544e64f) and on 2.0.0 (54ce0f7).

✅ Expected Behavior

A Worker that hosts a Channel starts, the way the runtime on its own does now (the runtime docs' Cloudflare Workers section; #7609, #8108). A Channel the runtime activates through Intelligence then finds @copilotkit/channels-intelligence in the bundle. If the package really is missing, the "install it" message shows up on workerd too.

Possible fixes, but you know the constraints better than I do:

  • channels-core: put the package name and version in at build time, the way fix(runtime): let the v2 runtime start on Cloudflare Workers #7609 did for the runtime, and run scripts/validate-module-scope-create-require.ts on channels-core in its check-dts too (today only the runtime runs it).
  • runtime: the variable specifier is deliberate (so the CJS build has no static ESM dependency). A literal import() only in the ESM build, or a public option to pass the module in (ActivateChannelEngine is only a test seam today), would let bundlers include it. Also count workerd's No such module as module-not-found.

Separate question, not part of the bug: a managed Channel keeps the Intelligence socket open, so a Worker that handles one request at a time may not be the right place for it, and a Durable Object might be. Do you plan to support Channels on Workers, or should it stay Node-only and say so in the docs? I'm happy to open a PR for the two fixes above once you've picked an approach.

❌ Actual Behavior

  • Any Worker that imports @copilotkit/channels-core fails to start: Uncaught TypeError: The argument 'path' … Received 'undefined' at node:module createRequire (step 1). The runtime on its own starts and serves runs on the same setup.
  • With that line patched, a Channel activated by the runtime through Intelligence never activates: ChannelManager.ready rejects with 1 channel(s) failed to activate or settle in time. The log shows the raw Error: No such module "@copilotkit/channels-intelligence" instead of the runtime's "install it" message, although the package is installed (step 3).

Logs for both are in the Logs field below.

Screenshots

No response

𝌚 CopilotKit Version

├── @copilotkit/[email protected]
├── @copilotkit/[email protected]
├── @copilotkit/[email protected]


Also reproduced with `@copilotkit/[email protected]`, `@copilotkit/[email protected]`, and `@copilotkit/[email protected]`. wrangler 4.166.0, `compatibility_date = "2026-11-01"`, macOS.

📄 Logs (Optional)

# step 1: npx wrangler dev -c core.toml
✘ [ERROR] service core:user:core: Uncaught TypeError: The argument 'path' The argument must be a file URL object, a file URL string, or an absolute path string.. Received 'undefined'
    at null.<anonymous> (node:module:34:15) in createRequire
    at null.<anonymous> (core.js:8834:11)
✘ [ERROR] The Workers runtime failed to start. There was likely a problem with the workerd binary or your configuration.

# step 3: npx wrangler dev -c managed.toml, then curl localhost:8787/
ready failed: ChannelManager.ready: 1 channel(s) failed to activate or settle in time
▲ [WARNING] {
    err: Error: No such module "@copilotkit/channels-intelligence".
        at importChannelsIntelligence (.../managed.js:141416:99)
        at defaultActivateChannel (.../managed.js:141419:17)
        at ChannelManager.activateChannel (.../managed.js:141664:75)
        ...
  } channel "repro" failed to activate

Activity

  1. added
    bug
    on Nov 23, 2026
  2. copilotkit-outpost-bot commented on Nov 23, 2026

    @copilotkit-outpost-bot

    ⚠️ This is an AI-generated response.

    This needs a maintainer review to give you a reliable next step.


    🤖 Generated by CopilotKit AI Support · Documentation


    Was this helpful? React with 👍 or 👎

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions