Repository navigation
Fetch doesn't work in 19.3.0 #46049
Description
Activity
This was fixed in nodejs/undici#1787 and undici was updated in #45812, it doesn't appear as though it made it into v19.3.0 though.
- addedfetchIssues and PRs related to the Fetch API.Issues and PRs related to the Fetch API.
on Jan 2, 2023 v19.4.0 have #45812 , so should be fixed by now in latest version (though I haven't tested it personally)
Note this bug made it into v18.13.0 as well. Related comment
Reacted by Jason LeoI'm still getting this bug in v18.14.2.
please post a new issue in https://github.com/nodejs/undici/ with a small repro
Downgrading to an older Node version (applicable to my case) fixes the issue.
this bug made it to node v18.16.0
@fawazahmed0 is there a fix for node 18.x?
I'd recommend using the fetch that undici exports, rather than the global one. Then you won't have to worry about old versions of node not receiving fixes or new features.
@KhafraDev so you are basically saying that using the global fetch in node should be deprecated and the fetch itself should be removed?
No, not at all. I'm saying that if there's an issue, for example, in v19.0.0 then you either have to update node to a version that ships undici's fix(es), or use undici itself.
The issue exists in v18.x versions as well (as other commenters pointed out)
Since Node 18 is still the actively supported version: https://nodejs.dev/en/about/releases till October 2023, one could expect that bug in the public API / feature would be fixed.Otherwise, if that's not the case, this feature should not be added to the Node itself.
Fetch is currently marked as experimental which means that it is "not recommended in production environments."1
However, I don't see anything that would prevent someone from backporting one of the undici updates to v18.x, it's just that no one has. Of course then you'll still have issues in older node 18 versions. Undici's fetch works from v16.8.0 to v20 so you don't need to deal with backports, buggy versions, and the like.
Footnotes
I just migrated node from v18.x to v21.7.0 hoping to solve this issue but I still get this error in production.
node:internal/deps/undici/undici:13737 Error.captureStackTrace(err, this); ^ TypeError: fetch failed at node:internal/deps/undici/undici:13737:13 at process.processTicksAndRejections (node:internal/process/task_queues:95:5) { [cause]: ConnectTimeoutError: Connect Timeout Error at onConnectTimeout (node:internal/deps/undici/undici:8285:28) at node:internal/deps/undici/undici:8237:50 at Immediate._onImmediate (node:internal/deps/undici/undici:8269:13) at process.processImmediate (node:internal/timers:478:21) { code: 'UND_ERR_CONNECT_TIMEOUT' } } Node.js v21.7.0My API call is entirely wrapped inside a try-catch. Should I stop using fetch?
selectionApiRouter.get('/selections/default/view', async (req: any, res) => { try { const currentMember: any = await sessionHelper.identifyMemberWithCookie(req, res) const calendarData = await calendarBuilder.buildCalendarViewData(currentMember) // (fetch inside) res.send(calendarData) } catch (error) { log.critical('API GET /selections/:slug/view', error) res.status(500).send({ error: 'Internal server error' }) } })
Version
19.3.0
Platform
Microsoft Windows NT 10.0.22000.0 x64
Subsystem
No response
What steps will reproduce the bug?
How often does it reproduce? Is there a required condition?
No response
What is the expected behavior?
No response
What do you see instead?
Additional information
The same code works fine in
v18.12.1If you are interested, here is my complete code: