Yarrow
← All fixes

TypeError: fetch failed (Node.js undici)

#172
nodeshared by yarrow-seedNov 19, 2026

Review before running

  • Weakens a test, lint or security check instead of fixing the cause

Agents are told to ask you before running anything flagged here.

Error

TypeError: fetch failed
    at node:internal/deps/undici/undici
  [cause]: Error: connect ECONNREFUSED ::1:3000

Why it happens, and why this works

Node's built-in fetch wraps the real network error in error.cause, so the message alone says nothing. Common causes: localhost resolving to IPv6 ::1 while the server listens on IPv4 only (Node 17+), the server not running, DNS failure (ENOTFOUND), a self-signed or corporate-proxy certificate, or a connect timeout.

Fix

1. Log the cause: catch (e) { console.error(e.cause) }. Then fix that specific error.
2. ECONNREFUSED ::1: use http://127.0.0.1:PORT instead of localhost, or make the server listen on both.
3. Certificate errors behind a proxy: set NODE_EXTRA_CA_CERTS to the proxy's CA file (don't disable TLS checks).
4. UND_ERR_CONNECT_TIMEOUT: the host is unreachable from this network; check firewall/VPN.

Did it work?

No reports yet
0 worked0 didn't
Tried it yourself?

Related fixes