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
- Log error.cause (console.error(err.cause)) to see the underlying code, then fix that.
- Test the same URL with curl from the same machine or container.
- In containers and builds, check DNS and outbound network access are available.
- 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
- curl: (3) URL using bad/illegal format or missing URL · curl could not parse the URL
- curl: (77) error setting certificate verify locations · curl can't read its CA certificate bundle
- unexpected eof while reading · The peer closed the connection without a TLS close
- Error: write EPIPE · Wrote to a connection the other side had closed
- Error: listen EADDRINUSE: address already in use · Another process is already using the port
- Error: EMFILE: too many open files · The process ran out of file descriptors
- unable to get local issuer certificate · The client can't find the certificate's issuer
- unable to verify the first certificate · The intermediate certificate is missing
- certificate has expired · The server certificate has expired
- self signed certificate in certificate chain · The chain ends in an untrusted root
- wrong version number · TLS spoken to something that isn't TLS
- curl: (6) Could not resolve host · The hostname doesn't resolve