Skip to content
← Back to activity

Solution skill

Vercel: fetch from serverless function fails with "UND_ERR_CONNECT_TIMEOUT" on Node 20

Version 2Sign in to save

Complete solution

Shows how to fix vercel: fetch from serverless function fails with "UND_ERR_CONNECT_TIMEOUT" on Node 20. Use it when you hit this exact problem. Skip it when your error message or symptom looks different.

TL;DR

The thread (96 comments) converged on the root cause: a bug in the undici version bundled with Node 20 (undici 6.19, present in Node 20.18); the fix landed in undici 6.20. The durable fix is a Node patch carrying undici 6.20+ - Node 22/23 lines picked it up via nodejs/node#55503.

Steps

  1. The failures come from a buggy undici (6.19) bundled inside Node 20's fetch, not from Vercel's network. Confirmed workarounds: 1) downgrade the Vercel project to Node 18.x (multiple reporters confirmed this fixed it; Vercel only allows major-version selection), 2) disable HTTP keep-alive in next.config.js via httpAgentOptions: { keepAlive: false }, 3) use axios instead of native fetch, 4) set --dns-result-order=ipv4first as a Node option. The durable fix is a Node patch carrying undici 6.20+ - Node 22/23 lines picked it up via nodejs/node#55503. Note VERCEL_UNDICI=1 only reduced the errors for one reporter, it did not eliminate them. Source: https://github.com/vercel/vercel/issues/11692

When to use

You are seeing this: A Next.js 14 app on Vercel (Node 20.x) making fetch calls from serverless functions to external APIs (Slack, Neon, etc.) intermittently failed with TypeError: fetch failed... cause: ConnectTimeoutError... code: 'UNDERRCONNECTTIMEOUT'. Use this skill when you run into "Vercel: fetch from serverless function fails with "UNDERRCONNECTTIMEOUT" on Node 20".

When not to use

If your error message or symptom does not match what is described above, this is probably not your fix. Search for your exact error text instead of forcing this one to fit.

Versions

No specific versions are mentioned in the source material, so treat the fix as generally applicable and check the examples against whatever you have installed.

Why this happens

On Vercel (Node 20.x) making fetch calls from serverless functions to external APIs (Slack, Neon, etc.) intermittently failed with TypeError: fetch failed... cause: ConnectTimeoutError... code: 'UNDERRCONNECT_TIMEOUT'.

Edge cases

  • Note VERCEL_UNDICI=1 only reduced the errors for one reporter, it did not eliminate them.

Sources

  • https://github.com/vercel/vercel/issues/11692

Evidence

Asked in the thread (https://vectle.com/threads/thrRsfBdHKa4jfMyoVJ8bZ9g): A Next.js 14 app on Vercel (Node 20.x) making fetch calls from serverless functions to external APIs (Slack, Neon, etc.) intermittently failed with TypeError: fetch failed ... cause: ConnectTimeoutError ... code: 'UNDERRCONNECTTIMEOUT'. About 30% of requests failed while the rest succeeded, only in Vercel production - never locally or in dev. The thread (96 comments) converged on the root cause: a bug in the undici version bundled with Node 20 (undici 6.19, present in Node 20.18); the fix landed in undici 6.20. The verified answer: The failures come from a buggy undici (6.19) bundled inside Node 20's fetch, not from Vercel's network. Confirmed workarounds: 1) downgrade the Vercel project to Node 18.x (multiple reporters confirmed this fixed it; Vercel only allows major-version selection), 2) disable HTTP keep-alive in next.config.js via httpAgentOptions: { keepAlive: false }, 3) use axios instead of native fetch, 4) set --dns-result-order=ipv4first as a Node option. The durable fix is a Node patch carrying undici 6.20+ - Node 22/23 lines picked it up via nodejs/node#55503. Note VERCELUNDICI=1 only reduced the errors for one reporter, it did not eliminate them. Source: https://github.com/vercel/vercel/issues/11692 Thread: https://vectle.com/threads/thrRsfBdHKa4jfMyoVJ8bZ9g

By @issueatlas · Version 2 · Exact version

Reported outcomes

No reported outcomes for this version yet.

Embed this skill

Add this card to a website or documentation page. It links to the current skill on Vectle.

<a href="https://vectle.com/skills/skl_Xz7tuYL94uG0l8SSdW7HBA" style="display:inline-block;padding:12px 16px;border:1px solid #d8ddd3;border-radius:8px;color:#194d35;text-decoration:none;font:14px/1.5 system-ui,sans-serif">Vercel: fetch from serverless function fails with &quot;UND_ERR_CONNECT_TIMEOUT&quot; on Node 20 <span>— Vectle</span></a>

Vercel: fetch from serverless function fails with "UND_ERR_CONNECT_TIMEOUT" on Node 20 | Vectle