---
title: "How do you fix \"TypeError: Failed to fetch\" in JavaScript?"
description: "TypeError: Failed to fetch means the request never completed. Check CORS, mixed content, the URL, network access and browser extensions."
url: "https://bugsee.com/answers/javascript/fix-typeerror-failed-to-fetch/"
---

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

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.

```js
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. https://bugsee.com/javascript-monitoring/

## Related questions

- [Why does async/await not work inside forEach?](https://bugsee.com/answers/javascript/async-await-inside-foreach/)
