openclaw - 💡(How to fix) Fix createRequire("undici") corrupts globalThis.fetch — all channel plugins using native fetch fail with TypeError

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…

When the gateway loads undici via createRequire(import.meta.url)("undici") in undici-runtime-DWGlO0I7.js, the resulting require("undici") call runs undici's index.js which calls setGlobalDispatcher(new Agent()) on a global Symbol. This corrupts the Node.js built-in globalThis.fetch, causing all subsequent native fetch calls to throw TypeError: fetch failed.

Root Cause

In Node.js v22, globalThis.fetch uses a built-in version of undici. When OpenClaw loads a different version of undici from its own node_modules/undici via createRequire, that version calls setGlobalDispatcher on its first load (in lib/global.js):

if (getGlobalDispatcher() === undefined) {
  setGlobalDispatcher(new Agent())
}

The two undici versions use the same Symbol key (Symbol.for("undici.globalDispatcher.2")) for the global dispatcher, but their dispatcher implementations are incompatible. Once overwritten, the built-in fetch uses the incompatible dispatcher and fails.

Fix Action

Fix / Workaround

Summary

When the gateway loads undici via createRequire(import.meta.url)("undici") in undici-runtime-DWGlO0I7.js, the resulting require("undici") call runs undici's index.js which calls setGlobalDispatcher(new Agent()) on a global Symbol. This corrupts the Node.js built-in globalThis.fetch, causing all subsequent native fetch calls to throw TypeError: fetch failed.

Root Cause

In Node.js v22, globalThis.fetch uses a built-in version of undici. When OpenClaw loads a different version of undici from its own node_modules/undici via createRequire, that version calls setGlobalDispatcher on its first load (in lib/global.js):

if (getGlobalDispatcher() === undefined) {
  setGlobalDispatcher(new Agent())
}

The two undici versions use the same Symbol key (Symbol.for("undici.globalDispatcher.2")) for the global dispatcher, but their dispatcher implementations are incompatible. Once overwritten, the built-in fetch uses the incompatible dispatcher and fails.

To Reproduce

  1. Start OpenClaw gateway with a channel plugin that uses native globalThis.fetch
  2. Observe all API calls fail with TypeError: fetch failed
  3. Workaround: Replace fetch with node:https in the plugin

Code Example

if (getGlobalDispatcher() === undefined) {
  setGlobalDispatcher(new Agent())
}
RAW_BUFFERClick to expand / collapse

Summary

When the gateway loads undici via createRequire(import.meta.url)("undici") in undici-runtime-DWGlO0I7.js, the resulting require("undici") call runs undici's index.js which calls setGlobalDispatcher(new Agent()) on a global Symbol. This corrupts the Node.js built-in globalThis.fetch, causing all subsequent native fetch calls to throw TypeError: fetch failed.

Impact

Any channel plugin that uses globalThis.fetch (e.g., the @tencent-weixin/openclaw-weixin plugin) stops working after the gateway starts. All fetch requests fail immediately with no actual network activity.

Root Cause

In Node.js v22, globalThis.fetch uses a built-in version of undici. When OpenClaw loads a different version of undici from its own node_modules/undici via createRequire, that version calls setGlobalDispatcher on its first load (in lib/global.js):

if (getGlobalDispatcher() === undefined) {
  setGlobalDispatcher(new Agent())
}

The two undici versions use the same Symbol key (Symbol.for("undici.globalDispatcher.2")) for the global dispatcher, but their dispatcher implementations are incompatible. Once overwritten, the built-in fetch uses the incompatible dispatcher and fails.

To Reproduce

  1. Start OpenClaw gateway with a channel plugin that uses native globalThis.fetch
  2. Observe all API calls fail with TypeError: fetch failed
  3. Workaround: Replace fetch with node:https in the plugin

Suggested Fix

  • Store a reference to the native fetch before loading undici
  • Or use the dispatcher option explicitly instead of relying on the global dispatcher
  • Or avoid require("undici") (which has this side effect) and use dynamic import instead

Environment

  • OpenClaw: 2026.5.20
  • Node.js: v22.22.2
  • OS: Linux (Alibaba Cloud Linux 3)
  • Affected plugin: @tencent-weixin/openclaw-weixin 2.1.8

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING

openclaw - 💡(How to fix) Fix createRequire("undici") corrupts globalThis.fetch — all channel plugins using native fetch fail with TypeError