Undici v8 is a significant release that modernizes the dispatcher handler API, raises the minimum Node.js version, and enables HTTP/2 by default. Most applications using the high-levelDocumentation Index
Fetch the complete documentation index at: https://mintlify.com/nodejs/undici/llms.txt
Use this file to discover all available pages before exploring further.
request, fetch, stream, or pipeline APIs will need minimal changes. If you maintain custom dispatchers, interceptors, or handlers that call dispatch() directly, you will need to update your handler callbacks before upgrading.
Before you upgrade
Check three things before installing undici v8:- Node.js version — v8 requires Node.js
>=22.19.0. Runnode -vand upgrade Node.js if needed. - Custom handlers — if you wrote custom dispatchers, interceptors, or handler objects passed to
dispatch(), review the handler API changes in steps 2 and 3. - HTTP/1.1-only code — if your application depends on HTTP/1.1 behavior (for example, it checks
connectionheaders or relies on upgrade handshakes), plan to setallowH2: falseexplicitly.
Breaking changes summary
Migration steps
Upgrade Node.js to v22.19.0 or later
Undici v8 requires Node.js If the output is lower than Once you are on Node.js 22.19.0 or later, install undici v8:
>=22.19.0. Verify your current version and upgrade if needed.v22.19.0, upgrade Node.js before proceeding. You can use a version manager such as nvm or fnm:Update custom handler callbacks
Undici v8 uses a unified dispatcher handler API (referred to internally as the v2 handler API). Every callback that a handler object can implement has been renamed. The controller argument replaces the inline
abort and resume callbacks.The full mapping is:| v7 callback | v8 callback |
|---|---|
onConnect(abort, context) | onRequestStart(controller, context) |
onHeaders(statusCode, rawHeaders, resume, statusText) | onResponseStart(controller, statusCode, headers, statusText) |
onData(chunk) | onResponseData(controller, chunk) |
onComplete(trailers) | onResponseEnd(controller, trailers) |
onError(err) | onResponseError(controller, err) |
onUpgrade(statusCode, rawHeaders, socket) | onRequestUpgrade(controller, statusCode, headers, socket) |
- Before (v7)
- After (v8)
Pause, resume, and abort via the controller
In v7, handlers could returnfalse from onData to signal backpressure, or store the abort reference passed to onConnect. In v8, all flow control goes through the controller object.- Before (v7)
- After (v8)
Raw headers and trailers
Raw header and trailer arrays are no longer passed directly as arguments. Read them from the controller:Update onBodySent handlers
If you implemented
onBodySent, its signature changed in v8. The handler no longer receives byte counters; it receives the actual chunk that was sent.- Before (v7)
- After (v8)
Use
onRequestSent() (no arguments) to receive a notification that the entire request body has been sent. This is the v8 equivalent of the v7 pattern of checking totalBytesSent in the final onBodySent call.Disable HTTP/2 if you need HTTP/1.1-only behavior
Undici v8 enables HTTP/2 by default when a TLS server advertises
h2 via ALPN during the TLS handshake. If your code relies on HTTP/1.1-specific behavior — for example, it inspects raw connection headers, uses HTTP/1.1 upgrade handshakes, or integrates with infrastructure that does not support HTTP/2 — set allowH2: false explicitly.- Before (v7)
- After (v8)
If you do not have a specific requirement to use HTTP/1.1, leave the default. HTTP/2 multiplexing can significantly improve throughput when connecting to servers that support it.
Replace fake Blob objects with real Blob or File instances
Undici v8 no longer accepts duck-typed Blob-like objects — objects that only appear to be
Blob instances by setting Symbol.toStringTag to 'Blob' or 'File'. You must pass actual Blob or File instances.- Before (v7)
- After (v8)
Replace direct global dispatcher symbol access with public APIs
Undici v8 changed the internal symbol used to store the global dispatcher from
Symbol.for('undici.globalDispatcher.1') to Symbol.for('undici.globalDispatcher.2'). If your code accessed the old symbol directly, migrate to the public setGlobalDispatcher and getGlobalDispatcher APIs.- Before (v7)
- After (v8)
Use Dispatcher1Wrapper for legacy v1 handler consumers (if needed)
Undici v8 ships a
Dispatcher1Wrapper compatibility shim. It wraps a v2-style dispatcher so that legacy consumers still using v1 handler callbacks (such as older versions of Node.js built-in fetch) can continue to work.You do not need this if you are only using undici directly. It is primarily useful when you need to expose a custom dispatcher to a consumer that calls v1-style handler callbacks internally.Dispatcher1Wrapper is exported from the top-level undici package. You do not need to import it from an internal path.Verify the upgrade
After updating your code, run your test suite against the areas most likely to be affected:
- Requests that use a custom
dispatcheroption setGlobalDispatcher()andgetGlobalDispatcher()behavior- Custom interceptors and retry handlers
- Uploads that use
Blob,File, orFormData - Integrations that depend on HTTP/1.1-only behavior
What’s new in v8
Beyond the breaking changes, v8 introduces several new capabilities:- HTTP/2 by default — connections to TLS servers that advertise
h2via ALPN now automatically use HTTP/2 multiplexing without any configuration. Dispatcher1Wrapper— a new export that wraps a v2-style dispatcher so it can be used by legacy v1 handler consumers, enabling gradual ecosystem migration.H2CClient— a new dispatcher for HTTP/2 cleartext (h2c) connections, exported directly from the undici package.RoundRobinPool— a new pool variant that distributes requests in a round-robin fashion across a set of clients.SnapshotAgent— a new mock utility for recording and replaying HTTP interactions in tests.deduplicateinterceptor — a new built-in interceptor that deduplicates concurrent identical requests, sending only one upstream request and sharing the response.decompressinterceptor — a new built-in interceptor that handles response decompression.