Best practices to work with undici.fetch in frameworks and libraries
#4595
Replies: 1 comment 1 reply
-
|
It really depends on the kind of experience you want to give. Using On the other hand, always keeping Another approach that I've seen is for libraries to use native My suggestion is to rely on
|
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Hello!
I want to ask for help choosing between a few approaches to working with
undici.Our case: we have a high-level universal HTTP request library based on
fetch, and an SSR application built on top of this library.First, we started migrating from
node-fetchtoglobalThis.fetchin our request library.After that, in the application code, we added
setGlobalDispatcher(new Agent()), whereAgentis imported fromundiciviarequire('undici').Agent.Then, some of our Jest tests started failing. After continuous debugging, I found that a simple
isErrorLikeutility returnsfalsefor undici'sSocketError, and we lose some properties likeerror.code.I think this is because Jest uses
node:vmto run tests. The details aren't very important for this case, but it's just an example of compatibility issues between external and bundled undici versions.So, my question is: which approach is preferable?
undiciversion independencies/peerDependencies, and importfetchfrom undiciglobalThis.fetch, relying on the Node.jsBeta Was this translation helpful? Give feedback.
All reactions