Failed to fetch
JavaScript Programming Language
Severity: ModerateWhat Does This Error Mean?
This error appears when JavaScript's fetch() function tried to make a network request but something went wrong before a response was received. The request never completed — it could be a network problem, a CORS restriction, a wrong URL, or the server being down. This is different from an HTTP error (like 404) — those are responses. This means no response arrived at all.
Affected Models
- All browsers
- Node.js (with node-fetch)
- Deno
- Any JavaScript runtime
Common Causes
- The device has no internet connection at the time of the request
- The URL in the fetch() call is incorrect or the server does not exist
- The request was blocked by CORS (the server does not allow requests from your website)
- The browser blocked the request because the page is HTTPS but the API is HTTP
- The server took too long to respond and the request timed out
How to Fix It
-
Open your browser console (F12 > Network tab). Look for the failed request in red. Click it to see the full details — URL, status, and error reason.
The Network tab shows every request the page made. A failed fetch will appear in red and often shows more detail than the Console tab.
-
Check the URL you are fetching. Copy it and paste it directly into your browser's address bar. If it does not load in the browser, the URL or server is the problem.
A typo in the URL is one of the most common causes. Even a missing letter or wrong domain will cause 'Failed to fetch'.
-
Check if the browser console shows a CORS error alongside the failed fetch. If so, the server needs to allow requests from your domain.
CORS errors look like: 'Access to fetch... has been blocked by CORS policy'. See the CORS error page for specific fixes.
-
Make sure you are not mixing HTTP and HTTPS. If your page is on HTTPS, fetch requests to HTTP URLs will be blocked by the browser.
This is called a 'mixed content' error. The fix is to use the HTTPS version of the API URL.
-
Add error handling to your fetch call so the error is caught gracefully: fetch(url).then(...).catch(err => console.error('Fetch failed:', err));
Always add a .catch() to your fetch calls. This prevents an unhandled rejection error and lets you show a friendly message to the user.
When to Call a Professional
If the error is happening in production and you control the server, you may need a backend developer to configure CORS headers. If you are just learning, this error is expected and fixable — check the URL, network connection, and CORS settings.
Frequently Asked Questions
What is the difference between 'Failed to fetch' and a 404 error?
A 404 error means the request reached the server but the server could not find the requested resource. The connection succeeded — there was just nothing at that URL. 'Failed to fetch' means the request never got a response at all. The connection itself failed, was blocked, or timed out before any response was received.
Why does 'Failed to fetch' happen in development but not on the live site?
This is common when your local development setup is on a different domain or port than the API. For example, your site runs on localhost:3000 but your API is on localhost:8080. Browsers treat these as different origins, so CORS rules apply. In production, both the site and API often share the same domain, which avoids the CORS issue entirely.
How can I test if a fetch request is working without writing code?
Use a free tool like Postman, Insomnia, or the curl command in a terminal. These tools send HTTP requests directly and show you exactly what the server returns. If the request works in Postman but fails in the browser, the problem is almost certainly CORS.