How do you fix "TypeError: Failed to fetch" in JavaScript?

← JavaScript answers

The browser could not complete the request at all, most often because of a CORS block, a mixed-content (http from https) request, a wrong URL or a network failure.

fetch only rejects when the request cannot be completed. An HTTP error such as 404 or 500 is a normal response, so Failed to fetch always points to something earlier than the server's answer.

  • CORS: the server must send Access-Control-Allow-Origin for your origin. The browser console names the blocked header; the fix is on the server.
  • Mixed content: a page served over https cannot call an http URL.
  • Wrong URL or server down: check the address, port and that the server is reachable.
  • Blockers: ad blockers, VPNs or proxies can cancel requests, so test in a clean profile.
try {
  const res = await fetch(url);
  if (!res.ok) throw new Error("HTTP " + res.status);
  const data = await res.json();
} catch (err) {
  console.error("Request failed:", err);
}
Network failures like this are hard to reproduce from a bug report. Bugsee records the request, its headers and the session leading up to it. Learn more

Related questions

Start debugging smarter today

Try Bugsee for free — no commitments, no hidden fees.

Free sign upLive demoNo credit card required