Skip to content
MtrXTools

TypeError: fetch failed

Node.js fetch failed below HTTP

Seen in Node.js 18+ fetch (undici), Next.js, SvelteKit, Nuxt

Node.js fetch failed before getting an HTTP response; the real reason is in the error cause printed below it.

Common causes

  • DNS failure (cause: getaddrinfo ENOTFOUND or EAI_AGAIN).
  • Connection refused or timed out (cause: ECONNREFUSED or UND_ERR_CONNECT_TIMEOUT).
  • TLS certificate problems (cause: UNABLE_TO_VERIFY_LEAF_SIGNATURE, CERT_HAS_EXPIRED and similar).
  • A proxy the network requires is not used, because Node.js fetch ignores HTTP_PROXY by default.

How to fix it

  1. Log error.cause (console.error(err.cause)) to see the underlying code, then fix that.
  2. Test the same URL with curl from the same machine or container.
  3. In containers and builds, check DNS and outbound network access are available.
  4. For corporate CAs, set NODE_EXTRA_CA_CERTS to the CA file rather than disabling verification.

Got a different message? Paste it into the error explainer.

Related errors

All 34 Command line & code errors