Fix Node 26+ compatibility (UND_ERR_INVALID_ARG) - #146
Open
IvanPleshkov wants to merge 2 commits into
Open
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fix: Node 26+ compatibility — UND_ERR_INVALID_ARG: invalid onError method
Fixes #134
On Node 26+ every request throws TypeError: fetch failed with cause UND_ERR_INVALID_ARG: invalid onError method.
This is the "two undici in one process" problem. The REST client pinned undici@^6 and built its own undici. Agent, then passed it as init. dispatcher to Node's global fetch. On Node ≤22, the bundled undici accepted the v6 Agent; Node 26 bundles undici 8.x, whose dispatcher hook contract is stricter and rejects the v6 Agent during dispatch init.
Fix
The request no longer flows through the global fetch with a foreign dispatcher. A terminal middleware now performs the request itself with a resolved fetch, picked in this order:
A - a caller-supplied fetch (new optional fetch option on QdrantClient);
B (default on Node) - undici's own fetch paired with an undici Agent from the same package, so the dispatcher contract always matches regardless of the undici version Node ships;
C - otherwise the platform's global fetch.
Notes:
The undici-backed transport lives in its own module (src/node-fetch.ts) and is referenced only behind a process guard.
The terminal middleware re-implements the dependency's response parsing, including the bigint reviver, so large-integer handling is preserved.
Public API is unchanged except for the new optional, backward-compatible fetch option.
How to reproduce / verify
Reproduced and verified with real client builds on
node:26-alpine(Node v26.3.1) against a local Qdrant-shaped HTTP server.repro.mjsfile:Run on Node 26: