TypeError: fetch failed
Node.js · updated 2026-11-05
Thrown by Node's built-in fetch (undici) when no response arrived at all: a DNS, TCP, TLS or socket failure. The message is always those two words; the specific failure sits in the error's cause property, which many loggers drop.
TypeError: fetch failed
at node:internal/deps/undici/undici:13510:13
at process.processTicksAndRejections (node:internal/process/task_queues:105:5)
at async getUser (/app/src/api.js:8:15) {
[cause]: Error: getaddrinfo ENOTFOUND api.internal.example
at GetAddrInfoReqWrap.onlookupall [as oncomplete] (node:dns:120:26) {
errno: -3008,
code: 'ENOTFOUND',
syscall: 'getaddrinfo',
hostname: 'api.internal.example'
}
}Quick fix
Print err.cause, not just err.message: it holds the real failure, such as ENOTFOUND, ECONNREFUSED, UND_ERR_CONNECT_TIMEOUT or a certificate error. Fix that underlying problem (hostname, port, firewall, proxy, CA bundle), and make your logger serialize the cause chain so the next occurrence explains itself.
- Catch the error and log err.cause and err.cause.code along with the URL.
- ENOTFOUND or EAI_AGAIN: fix the hostname or DNS inside that environment.
- ECONNREFUSED: start the target service or correct the port.
- UND_ERR_CONNECT_TIMEOUT: check firewalls, security groups and egress rules.
- Certificate errors: add your internal CA with NODE_EXTRA_CA_CERTS.
- Behind an HTTP proxy, route fetch through undici's EnvHttpProxyAgent or ProxyAgent.
try {
const res = await fetch(url);
// ...
} catch (err) {
const cause = (err as Error & { cause?: { code?: string; message?: string } }).cause;
console.error('fetch failed', {
url,
code: cause?.code,
reason: cause?.message ?? String(cause),
});
throw err;
}Paste this into Claude Code, Cursor or Codex in the project that throws it. The agent reads this guide in plain text and applies the fix that matches your stack.
Read https://runheed.com/errors/fetch-failed.md and fix this error in this project.Why it happens
DNS lookup failed (ENOTFOUND, EAI_AGAIN)
A typo in the hostname, an internal name that only resolves inside a VPC or cluster, or a container without working DNS. EAI_AGAIN means the resolver itself timed out or could not be reached, which is often transient.
Connection refused (ECONNREFUSED)
Nothing listens on that host and port. On Node before 18.18 or 20, a common local twist is localhost resolving to ::1 while the target server binds only 127.0.0.1.
Connect timeout (UND_ERR_CONNECT_TIMEOUT)
undici gives up on the TCP handshake after 10 seconds by default. Firewalls and security groups that silently drop packets produce a timeout rather than a refusal, so this cause points at network policy.
TLS verification failed
Self-signed certificates, private CAs and corporate TLS inspection show up as DEPTH_ZERO_SELF_SIGNED_CERT, SELF_SIGNED_CERT_IN_CHAIN or UNABLE_TO_VERIFY_LEAF_SIGNATURE in the cause. An expired certificate on the server shows CERT_HAS_EXPIRED instead.
Socket closed by the other side (UND_ERR_SOCKET)
The server or a proxy closed a pooled keep-alive connection that undici reused. Appears after idle periods when the upstream's keep-alive timeout is shorter than the client's.
Other fixes
- Point NODE_EXTRA_CA_CERTS at a PEM file containing your internal CA instead of disabling TLS verification.
- Use 127.0.0.1 instead of localhost when the local server listens on IPv4 only.
- Retry idempotent requests once when the cause is UND_ERR_SOCKET or ECONNRESET.
- Raise undici's connect timeout with a custom Agent only after confirming the network path is slow rather than blocked.
Same error, other wording
- TypeError: fetch failed [cause]: Error: getaddrinfo ENOTFOUND
- TypeError: fetch failed [cause]: ConnectTimeoutError: Connect Timeout Error
- TypeError: fetch failed [cause]: SocketError: other side closed
- TypeError: Failed to fetch
Let your coding agent catch the next one
Runheed records this error in production with the stack trace, the breadcrumbs before it and, when you set it, the agent session that shipped the code, and serves it to Claude Code, Cursor or any MCP client. With it connected, you can ask:
> Pull the recent "TypeError: fetch failed" errors from production, find the calling code from each stack, send err.cause and the URL as extra data at those calls, then fix the largest group once the causes show up.
Setup for Supabase Edge Functions, Vercel Functions or AWS Lambda (Node.js and Python), then have your agent fix and resolve it.
Related errors
- Error: read ECONNRESET
- Error: connect ECONNREFUSED 127.0.0.1:5432
- SyntaxError: Unexpected token '<', "<!DOCTYPE "... is not valid JSON
More in Network and HTTP
- Error: connect ETIMEDOUT 10.0.4.12:5432Node.js
- Error: self-signed certificate in certificate chainNode.js
- Error: getaddrinfo ENOTFOUND api.example.comNode.js
- Error: write EPIPENode.js
- Access to fetch at 'https://api.example.com/orders' from origin 'https://app.example.com'...Node.js
- AxiosError: Request failed with status code 401Node.js
- FunctionsHttpError: Edge Function returned a non-2xx status codeSupabase
- requests.exceptions.ConnectionError: HTTPSConnectionPool(host='api.example.com'...Python
- httpx.ReadTimeout: The read operation timed outPython
- ConnectionResetError: [Errno 104] Connection reset by peerPython
- BrokenPipeError: [Errno 32] Broken pipePython
- [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer...Python
- Error [ERR_HTTP_HEADERS_SENT]: Cannot set headers after they are sent to the clientNode.js
- 422 Unprocessable Entity: {"detail":[{"type":"missing","loc":["body","email"],"msg":"Field...Python
- No signatures found matching the expected signature for payload. Are you passing the raw...Node.js
- TokenExpiredError: jwt expiredNode.js
- Error: 429 You exceeded your current quota, please check your plan and billing details.Node.js
Other error topics
- django.db.utils.OperationalError: no such table: orders_orderDatabases
- error: null value in column "total" of relation "orders" violates not-null constraintDatabases
- PrismaClientKnownRequestError: Unique constraint failed on the fields: (`email`)Databases
- Error: Could not load the "sharp" module using the linux-x64 runtimeImports and modules
- Module not found: Can't resolve 'fs'Imports and modules
- AttributeError: module 'requests' has no attribute 'get'Imports and modules
- Hydration failed because the server rendered HTML didn't match the client. As a result...React and Next.js rendering
- Error: NEXT_REDIRECTReact and Next.js rendering
- Objects are not valid as a React child (found: object with keys {id, name, total}). If...React and Next.js rendering
- TypeError: __init__() got an unexpected keyword argument 'proxies'Undefined, None and type errors
- java.lang.NullPointerException: Cannot invoke "String.toLowerCase()" because the return...Undefined, None and type errors
- TypeError: 'NoneType' object is not subscriptableUndefined, None and type errors
- ZodError: [ { "expected": "string", "code": "invalid_type", "path": [ "email" ]...JSON, parsing and validation
- TypeError: Object of type datetime is not JSON serializableJSON, parsing and validation
- SyntaxError: Unexpected end of JSON inputJSON, parsing and validation
- [UnhandledPromiseRejection: This error originated either by throwing inside of an async...Memory, async and the process
- Error: listen EADDRINUSE: address already in use :::3000Memory, async and the process
- Error: EMFILE: too many open files, open '/app/uploads/0412.jpg'Memory, async and the process
- McpError: MCP error -32000: Connection closedMCP servers and clients
- Error: spawn npx ENOENTMCP servers and clients
- ModuleNotFoundError: No module named 'mcp.server.fastmcp'MCP servers and clients
Free tools: Source map stack trace decoder · Uptime and SLA downtime calculator · Error budget calculator · Stack trace formatter · JSON log viewer · HTTP status code reference.
References: Node.js globals: fetch, Node.js CLI: NODE_EXTRA_CA_CERTS, MDN: Error.prototype.cause
Spotted a mistake? Email hello@greatwork.company. About Runheed.