Fix guides · Lovable, Bolt, v0, Cursor, Claude Code, Replit ·
Fix "Failed to fetch" error in browser (CORS, localhost & more)
TypeError: Failed to fetch
"TypeError: Failed to fetch" means the browser couldn't complete the request at all, so there is no status code to read. The usual causes are a CORS block, a wrong or unreachable URL (often localhost in a deployed app), an http API called from an https page, or a server that's down or crashed. The Network tab and the console line just above the error tell you which one it is.
Common causes – and how to tell which one you have
1. CORS blocked the response
How to tell: The console shows a red CORS message such as "No 'Access-Control-Allow-Origin' header" right before Failed to fetch, and the request in the Network tab shows a CORS error.
Fix: Add the right CORS headers on the server for your site's exact origin, and answer OPTIONS preflight requests. If you don't control the API, call it from your own backend or serverless function instead of the browser.
2. The URL points to localhost or an old address
How to tell: It works on your machine but fails after deploying, or the request in the Network tab goes to http://localhost:3000, 127.0.0.1 or an old preview URL.
Fix: Put the API base URL in an environment variable, set the production value on your host (for example Vercel or Netlify) and redeploy. In the browser, use a relative path like /api/... when the API is on the same site.
3. Mixed content: http API from an https page
How to tell: Your site is on HTTPS and the request goes to an HTTP URL. The console mentions 'Mixed Content' and the request is blocked.
Fix: Call the API over HTTPS. If the server doesn't support HTTPS, proxy it through your own backend.
4. The server is down, crashed or the domain is wrong
How to tell: The Network tab shows the request as failed with something like ERR_CONNECTION_REFUSED or ERR_NAME_NOT_RESOLVED, and opening the URL directly in a new tab also fails.
Fix: Check the spelling of the URL and that the backend is running. Look at your server or function logs for a crash, fix it, and redeploy.
5. Blocked by an ad blocker or browser extension
How to tell: It fails only in your browser, the URL contains words like analytics, track or ads, and it works in a private window without extensions.
Fix: Check whether an ad blocker or privacy extension is blocking the request. If so, the app should degrade gracefully — show a clear message to the user instead of silently failing. Do not rename the endpoint path to work around the blocker.
How to fix it
- Open the browser DevTools (F12), go to the Console and read the message just above "Failed to fetch" — CORS, Mixed Content or a connection error.
- Go to the Network tab, trigger the request again and click the failed request. Check the full URL: is it localhost, a plain http address instead of https, or a typo?
- Paste the URL into a new browser tab or run curl -i <url>. If it doesn't answer, fix or start the server first.
- If the console shows a CORS message, add Access-Control-Allow-Origin for your site's origin on the server and handle OPTIONS requests.
- Move the API base URL into an environment variable, set the production value on your host and redeploy.
- Wrap the call in try/catch and show the user a friendly error, then confirm in the Network tab that the request now returns a status code like 200.
Using Lovable, Bolt or v0?
In Lovable, Bolt or v0, tell the AI: "Requests fail with 'TypeError: Failed to fetch'. Check the browser console for a CORS or Mixed Content message, check the URL isn't localhost, and handle the error so the app shows a message instead of breaking." If the request goes to a Supabase Edge Function, check its logs in the Supabase Dashboard and that it returns CORS headers. Copy the full console message (the line above Failed to fetch) into the chat, because that's what says which cause it is.
Using Cursor, Claude Code or Windsurf?
Ask Cursor or Claude Code to list every fetch call and its URL, show where the base URL comes from, and check it against your production environment variables. Have it reproduce the request with curl -i to see whether the server answers at all and whether Access-Control-Allow-Origin is present, then confirm in the browser Network tab that the request returns a real status code.
The “fix” to avoid
Adding mode: 'no-cors' to the fetch call hides the error instead of solving it — the response returns status 0 with an unreadable body. This makes the app look like it's blocked rather than failing. The real fix is to ensure CORS headers are set on the server or serve over HTTPS.
Copy-paste fix prompt for your AI coding tool
Paste this into Cursor, Claude Code, Lovable or Bolt:
My app throws "TypeError: Failed to fetch". Find the failing fetch call and check, in this order: 1) is the URL correct for the environment it runs in (no localhost or old preview URL in production; the base URL comes from an environment variable)? 2) is it an HTTP URL called from an HTTPS page (mixed content)? 3) does the server send Access-Control-Allow-Origin for my origin and answer OPTIONS preflight? 4) is the server reachable at all (test with curl -i)? Fix the actual cause. Do not add mode: 'no-cors' and do not silently swallow the error; add a try/catch that shows the user a clear message. Tell me which cause it was and verify the request returns a real status code in the browser's Network tab.
Questions people ask
Why is there no status code with Failed to fetch?
Because the browser never received a response it was allowed to read. The request was blocked (CORS, mixed content, extension) or the connection failed, so there's nothing like a 404 or 500 to show.
It works locally but fails after deploying. Why?
Most often the code still calls http://localhost or the production API doesn't allow your live domain in its CORS settings. Check the request URL in the Network tab on the live site.
Is 'Load failed' in Safari the same error?
Yes. Safari says 'Load failed' and Firefox says 'NetworkError when attempting to fetch resource' for the same kind of failure, and the same causes apply.