
Node 26 Fetch Dispatcher: invalid onError method - 3 Fixes
Skilldham
Engineering deep-dives for developers who want real understanding.
Last updated: November 2026
TL;DR
This Node 26 fetch dispatcher error means two undici versions collided. A dispatcher only works with the undici that created it.
Node 26 bundles undici 8. An Agent or ProxyAgent from undici 6 or 7 breaks global fetch.
undici 6 dispatcher: throws UND_ERR_INVALID_ARG: invalid onError method
undici 7 dispatcher: no error, but headers vanish and gzip or Brotli bodies stay compressed
Fix: import fetch from your undici, upgrade undici to v8, or use NODE_USE_ENV_PROXY
You bump the Docker image from node:24 to node:26. Node 26 went LTS on 28 October, so it feels like the safe move.
The build passes. The deploy goes green.
Then the first outbound request dies with this:
bash
InvalidArgumentError: invalid onError method
code: 'UND_ERR_INVALID_ARG'Or worse, nothing throws at all. The response arrives, but content-type is null. Then res.json() chokes on compressed bytes.
You did not touch the HTTP code. That is the maddening part.
Most fixes online tell you to npm i undici and pass its ProxyAgent to fetch. On Node 26, that advice is the bug.
Here is the rule behind the Node 26 fetch dispatcher mismatch. Then the culprit check and three fixes that work.
Node 26 Fetch Dispatcher Error: Two Symptoms, One Cause
The same bug shows up two ways. Which one you get depends on the undici major you installed. Both start with a custom dispatcher passed to the built-in fetch.
The Thrown Version (undici 6 Dispatcher)
javascript
// Wrong: Agent from undici 6, fetch from Node 26 (undici 8)
import { Agent } from 'undici'; // package.json: "undici": "^6.21.0"
const agent = new Agent({ keepAliveTimeout: 10_000 });
const res = await fetch('https://api.example.com/users', {
dispatcher: agent,
});On Node 26 this throws before the request leaves the machine. The Qdrant JS client hit exactly this on its first request. It built an Agent from undici 6 and handed it to global fetch.
Here is a real trace from node-gyp on Node 26.1.0, reported in nodejs/node issue #63757:
bash
gyp ERR! stack InvalidArgumentError: invalid onError method
gyp ERR! stack at EnvHttpProxyAgent.dispatch
(...\node_modules\npm\node_modules\undici\lib\dispatcher\dispatcher-base.js:188:15)
gyp ERR! stack at node:internal/deps/undici/undici:13941:57Read the two paths. The EnvHttpProxyAgent lives in node_modules.
The caller lives in node:internal/deps/undici. That is two undici copies inside one request.
The Silent Version (undici 7 Dispatcher)
javascript
// Wrong: Agent from undici 7, fetch from Node 26 (undici 8)
import { Agent } from 'undici'; // package.json: "undici": "^7.22.0"
const agent = new Agent({ connections: 10 });
const res = await fetch('https://api.example.com/users', {
dispatcher: agent,
});
console.log(res.status); // 200
console.log(res.headers.get('content-type')); // null
const data = await res.json(); // throws: body is still compressedThis one is nastier. The status is 200, so health checks pass. The undici team tracks it in issue #5341, reported on Node 26.3.0.
The @vercel/sandbox SDK broke this way on Node 26.1.0. It shipped undici 7.22.0 internally. Response headers did not surface, and Brotli bodies were never decoded.
Without content-encoding, fetch has no reason to decompress. Your JSON parser gets raw compressed bytes.

Why It Breaks: A Dispatcher Belongs to One undici
Global fetch in Node is not magic. It is a copy of undici, compiled into the Node binary. Your node_modules can hold another copy.
Node Bundles Its Own undici
Check the bundled version yourself:
bash
node -p "process.versions.undici"
# Prints an 8.x version on any Node 26 releaseRunning npm i undici installs a second, separate copy. Each copy has its own Agent, ProxyAgent and fetch.
They look identical in your editor. They are not identical at runtime.
The Handler Interface Changed in undici 8
A dispatcher and fetch talk through a handler object. Older dispatchers expect methods like onError, onHeaders and onData.
undici 7 still accepted those 6.x style handlers. undici 8 does not.
So Node 26’s fetch passes a new-style handler. An undici 6 dispatcher looks for onError, finds nothing, and throws. The error message is literal.
An undici 7 dispatcher accepts the handler without complaint. But the hand-off drops the response headers. The exact cause is still under discussion in #5341.
Node and undici Version Matrix
Node.jsBundled undiciOlder dispatcher behavior226.xBaseline247.xundici 6 dispatcher still works268.xundici 6 throws, undici 7 drops headers
The whole bug fits in one line. A dispatcher only works with the undici that created it. Node 24 forgave the mismatch. Node 26 does not.
Find the Package That Triggers It
Most teams never import undici directly. An SDK does it for them. So find the culprit before you change code.
Run npm ls undici
bash
# Correct: list every undici copy in the tree
npm ls undici --allExample output for a project with one direct and one transitive copy:
bash
my-api@1.0.0
├─┬ @acme/vector-sdk@2.4.0
│ └── undici@6.21.1
└── undici@7.22.0Any copy below 8 is a suspect. That alone does not prove a break. A copy only matters when its dispatcher reaches global fetch.
Search for the dispatcher Option
bash
# Your own code
grep -rn "dispatcher" src/
# The suspect SDK from npm ls
grep -rln "dispatcher" node_modules/@acme/vector-sdk/distA hit next to a plain fetch( call is your bug. A hit next to undici.fetch( or request( is safe. Those calls use the same copy.
Read the Stack Trace Paths
For the thrown version, the trace names the culprit. A frame under node_modules/.../undici/ is the old dispatcher. Frames under node:internal/deps/undici are Node’s fetch.
For the silent version, there is no trace. Log process.versions.undici next to the failing call. Then compare it with npm ls.
Fix A: Import fetch From the Same undici
This is the most robust fix. It works on Node 22, 24 and 26. It also survives the next bundled undici bump.
javascript
// Wrong: dispatcher and fetch come from different undici copies
import { ProxyAgent } from 'undici';
const proxy = new ProxyAgent(process.env.HTTPS_PROXY);
const res = await fetch('https://api.example.com/users', { dispatcher: proxy });The fetch here is global. It comes from Node 26’s undici 8. The ProxyAgent comes from whatever node_modules holds.
javascript
// Correct: fetch and ProxyAgent come from the same undici
import { fetch, ProxyAgent } from 'undici';
const proxy = new ProxyAgent(process.env.HTTPS_PROXY);
const res = await fetch('https://api.example.com/users', {
dispatcher: proxy,
});
console.log(res.headers.get('content-type')); // application/json
const data = await res.json();One import line changes. Both objects now share one handler interface. Node’s bundled version stops mattering.
The digitalbazaar http-client took this route for Node 26. So did the Apache TinkerPop JS driver.
The Request Object Gotcha
undici’s fetch does not accept a global Request object. The http-client fix hit this with ky, which passes Request instances.
javascript
// Wrong: global Request passed to undici's fetch
import { fetch as undiciFetch, ProxyAgent } from 'undici';
const proxy = new ProxyAgent(process.env.HTTPS_PROXY);
const req = new Request('https://api.example.com/users', { method: 'POST', body: '{}' });
await undiciFetch(req, { dispatcher: proxy });javascript
// Correct: unpack the Request into a url and an init object
import { fetch as undiciFetch, ProxyAgent } from 'undici';
const proxy = new ProxyAgent(process.env.HTTPS_PROXY);
export async function fetchWithProxy(req) {
const hasBody = !['GET', 'HEAD'].includes(req.method);
return undiciFetch(req.url, {
method: req.method,
headers: Object.fromEntries(req.headers),
body: hasBody ? await req.arrayBuffer() : undefined,
signal: req.signal,
dispatcher: proxy,
});
}Reading the body as an ArrayBuffer avoids passing a stream across copies. That keeps the two undici versions fully apart.
Watch Your instanceof Checks
undici’s fetch returns undici’s own Response class. Node’s global Response comes from the bundled copy. So res instanceof Response can return false.
javascript
// Wrong: breaks when the Response came from installed undici
if (res instanceof Response) {
return res.json();
}
// Correct: check the shape, not the class
if (res && typeof res.json === 'function') {
return res.json();
}This is the second-order bug most teams hit after Fix A. Search for instanceof Response before you ship.
Fix B: Upgrade the undici Dependency to v8
If you own the dependency, upgrade it. Your Agent then speaks the same handler interface as Node 26’s fetch.
Upgrade a Direct Dependency
bash
npm i undici@^8
npm ls undici --alljavascript
// Correct on Node 26: undici 8 Agent with global fetch
import { Agent } from 'undici'; // package.json: "undici": "^8.0.0"
const agent = new Agent({ keepAliveTimeout: 10_000 });
const res = await fetch('https://api.example.com/users', {
dispatcher: agent,
});Read the undici 8 release notes before you bump. A major version changes more than handlers. Check the engines field against every Node version you still run.
Handle a Transitive Dependency
If an SDK pins undici 6 or 7, upgrade the SDK first. Many have shipped Node 26 fixes already. Vercel’s sandbox SDK fixed it in PR #220.
If no fix exists yet, npm overrides can force a version:
json
{
"overrides": {
"undici": "^8.0.0"
}
}Treat this as a stopgap. You are forcing a major the SDK never tested. Run its integration tests, then audit the result with the npm lockfile check.
The Reverse Trap on Node 24
Fix B ties you to Node 26. Run the same code on Node 24 and the roles flip. An undici 8 dispatcher then meets undici 7’s fetch.
That is still two copies, just reversed. During a rolling upgrade, some pods run 24 and some run 26. Use Fix A there.
Fix C: Drop the Agent and Use Built-In Proxy Support
Many teams only built a ProxyAgent for a corporate proxy. Node now handles that natively. No undici import means no mismatch.
Use NODE_USE_ENV_PROXY
bash
# Correct: let Node read the proxy env vars (Node 24.5 and later)
NODE_USE_ENV_PROXY=1 \
HTTPS_PROXY=http://proxy.corp.internal:8080 \
NO_PROXY=localhost,127.0.0.1 \
node server.jsNode reads HTTP_PROXY, HTTPS_PROXY and NO_PROXY. The --use-env-proxy flag does the same job. Delete the ProxyAgent and the dispatcher option.
Use http.setGlobalProxyFromEnv()
Some platforms will not let you set env vars before boot. Turn proxy support on from code instead.
javascript
// Correct: enable proxy support at runtime (Node 24.14+ or 25.4+)
import http from 'node:http';
const restore = http.setGlobalProxyFromEnv({
https_proxy: 'http://proxy.corp.internal:8080',
no_proxy: 'localhost,127.0.0.1,.internal.example.com',
});
const res = await fetch('https://api.example.com/users');
console.log(res.headers.get('content-type'));
// In tests: restore();Call it with no argument to read process.env. The return value restores the old settings. The Node.js http.setGlobalProxyFromEnv docs list every option.
When Fix C Is Not Enough
Fix C only covers proxies. It does not tune keep-alive or pool size. If your Agent existed for keepAliveTimeout or connections, use Fix A or Fix B.
Also ask whether you still need that tuning. Remove the dispatcher option and fetch uses its default pool. Measure first, then decide.
Catch the Mismatch Before Production
This bug passes builds. It fails on the first real request. So check versions where the image is built.
Dockerfile Before and After
dockerfile
# Wrong: base image bumped, nothing checks undici
FROM node:26-bookworm-slim
WORKDIR /app
COPY package*.json ./
RUN npm ci --omit=dev
COPY . .
CMD ["node", "server.js"]dockerfile
# Correct: print both undici versions during the build
FROM node:26-bookworm-slim
WORKDIR /app
COPY package*.json ./
RUN npm ci --omit=dev
RUN node -p "'bundled undici: ' + process.versions.undici" \
&& (npm ls undici --all || true)
COPY . .
CMD ["node", "server.js"]The || true keeps the build alive when undici is absent. Native add-ons can break on the same bump. The Node 24 native module Docker build fix covers that rebuild step.
Add a CI Guard That Fails Fast
javascript
// Correct: scripts/check-undici.mjs fails CI on an older undici copy
import { execSync } from 'node:child_process';
const bundledMajor = Number(process.versions.undici.split('.')[0]);
let tree = {};
try {
tree = JSON.parse(execSync('npm ls undici --all --json', { encoding: 'utf8' }));
} catch (err) {
tree = JSON.parse(err.stdout || '{}');
}
const found = [];
function walk(deps = {}, path = []) {
for (const [name, info] of Object.entries(deps)) {
const here = [...path, `${name}@${info.version}`];
if (name === 'undici' && info.version) found.push(here.join(' > '));
walk(info.dependencies, here);
}
}
walk(tree.dependencies);
const stale = found.filter((chain) => {
const version = chain.split('undici@').pop();
return Number(version.split('.')[0]) < bundledMajor;
});
if (stale.length) {
console.error(`Node bundles undici ${process.versions.undici}. Older copies found:`);
stale.forEach((chain) => console.error(' ' + chain));
process.exit(1);
}
console.log('undici check passed');Add "check:undici": "node scripts/check-undici.mjs" to your scripts. Run it in CI on the same Node image you deploy.
A failure is a review prompt, not proof. Then grep that package for dispatcher. If it uses undici’s own fetch, it is safe.
Key Takeaways
A Node 26 fetch dispatcher error means your dispatcher and fetch come from different undici copies.
Node 22 bundles undici 6, Node 24 bundles undici 7, and Node 26 bundles undici 8.
An undici 6 dispatcher throws invalid onError method on Node 26.
An undici 7 dispatcher fails silently: missing headers and undecoded gzip or Brotli bodies.
Run npm ls undici --all to find the copy, often inside an SDK.
Fix A, importing fetch from your undici, works on every Node version.
For proxies only, NODE_USE_ENV_PROXY=1 removes the need for a dispatcher.
Check process.versions.undici in your Docker build, not in production logs.
FAQ
What does “invalid onError method” mean on Node 26?
Your dispatcher comes from undici 6, but fetch comes from Node’s bundled undici 8. The old dispatcher expects a handler with an onError method. undici 8 sends a new-style handler without it, so the dispatcher throws UND_ERR_INVALID_ARG.
Why does fetch return no headers with a custom Agent on Node 26?
That is the undici 7 version of the same mismatch. The request succeeds, but response headers do not surface. Without content-encoding, gzip and Brotli bodies stay compressed, so res.json() fails.
Which undici version does Node 26 bundle?
Node 26 bundles undici 8. Run node -p "process.versions.undici" to see the exact version. Node 24 bundles undici 7 and Node 22 bundles undici 6.
Why did the same code work on Node 24?
Node 24’s undici 7 still accepted the older 6.x style handlers. So an undici 6 dispatcher kept working by accident. undici 8 removed that compatibility, which is why the break appears only after the upgrade.
Can I just remove the dispatcher option?
Yes, if the dispatcher only tuned pool or keep-alive settings. Global fetch then uses its default pool. If it routed traffic through a proxy, use NODE_USE_ENV_PROXY=1 or http.setGlobalProxyFromEnv() instead.
Should I use npm overrides to force undici 8?
Only as a short-term stopgap. Overrides force a major version the SDK never tested. Upgrade the SDK when it ships a Node 26 fix, then remove the override.
Do I still need the undici package on Node 26?
Not for plain fetch. You need it only for classes Node does not expose, like Agent and ProxyAgent. If you install it, import fetch from the same package.
Will this happen again on future Node versions?
It can, whenever Node bundles a new undici major. Fix A protects you because both objects always come from one copy. Keep the CI guard so the next bump fails in the pipeline.
Conclusion
A dispatcher only works with the undici that created it. Node 26 made that rule strict, so old SDK code now throws or quietly loses headers. Run npm ls undici --all today, before the first production request finds it for you.
Many teams moved to Node 26 for the October security patches. Did that include the Node.js Brotli RCE fix? Check your undici tree in the same pull request.
Want the next Node breaking change explained before it hits your pipeline? Join the SkillDham newsletter for one practical fix every week.