Repository navigation
Description
♻️ 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.tomlnpx wrangler dev -c core.toml. The Worker doesn't start (log below). That'sconst pkg = createRequire(import.meta.url)("../package.json")at the top ofchannels-core/dist/create-channel.js(source:packages/channels-core/src/create-channel.ts:70-72). workerd leavesimport.meta.urlundefined, so the call throws while the module loads.pkgis only used for telemetry (packageName/packageVersion).- 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, thencurl localhost:8787/printsfunction. (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.) npx wrangler dev -c managed.toml, thencurl localhost:8787/printsready failed: ChannelManager.ready: 1 channel(s) failed to activate or settle in time, and the log showsError: No such module "@copilotkit/channels-intelligence".defaultActivateChannelloads the package withimport(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, becauseisModuleNotFoundonly checksERR_MODULE_NOT_FOUND/MODULE_NOT_FOUND, and workerd throws a plainErrorwithout acode.- If I also change that line in
dist/v2/runtime/core/channel-manager.mjsto a literal, the error goes away andcurlprintsready() still pending after 3s:With ased -i '' 's#() => import(CHANNELS_INTELLIGENCE_SPECIFIER)#() => import("@copilotkit/channels-intelligence")#' node_modules/@copilotkit/runtime/dist/v2/runtime/core/channel-manager.mjs
WebSocketspy in the same Worker, I can see activation openws://127.0.0.1:9/socket/channels/websocket?vsn=2.0.0through the globalWebSocketand 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.tson channels-core in itscheck-dtstoo (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 (ActivateChannelEngineis only a test seam today), would let bundlers include it. Also count workerd'sNo such moduleas 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-corefails to start:Uncaught TypeError: The argument 'path' … Received 'undefined'atnode:modulecreateRequire(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.readyrejects with1 channel(s) failed to activate or settle in time. The log shows the rawError: 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
copilotkit-outpost-bot commentedon Nov 23, 2026
This needs a maintainer review to give you a reliable next step.
🤖 Generated by CopilotKit AI Support · Documentation
Was this helpful? React with 👍 or 👎
fix(channels-core,runtime): fix Cloudflare Workers compatibility