Home·Error messages

chrome · JavaScript

The message

TypeError: Failed to fetch

What it means

The request ended without a response, and the browser deliberately hides the reason: a CORS block, a dead address, a bad certificate, and an ad-blocking extension all produce these same two words. This is a thrown error rather than a status, so a 404 or a 500 never reaches it — the server never got as far as answering. There is often a second, more specific line just above it in the console or in the Network tab, so read that first, and hitting the URL with curl -i separates "the server is down" from "the browser refused". Firefox words the same situation as NetworkError when attempting to fetch resource.

The fix

curl -i https://api.example.com/data
Printed by
chrome
JavaScript
15

Browser and Node errors usually tell you what broke and not why the value became what it was — you read undefined, it was not a function, it was not JSON — so the place to fix is upstream of the line that threw, and silencing just that line with ?. and default values makes the same problem reappear further away in a form that is harder to recognise.

Reading an error message

  • Read from the first line down. The lower you go the more it is about the tool’s internals; the cause is usually at the top.
  • If there is a file and a line number, start there — not the top stack frame, but the topmost line that names a file you wrote.
  • Search the message verbatim, but strip your own paths and variable names first; those are what stop the search from matching.
  • The same condition is worded differently across tool versions. If results look wrong, add the version number to the query.
  • Before pasting a fix, check what it throws away. Some of these cannot be undone.

Common questions

Q. What does “TypeError: Failed to fetch” mean?

The request ended without a response, and the browser deliberately hides the reason: a CORS block, a dead address, a bad certificate, and an ad-blocking extension all produce these same two words. This is a thrown error rather than a status, so a 404 or a 500 never reaches it — the server never got as far as answering. There is often a second, more specific line just above it in the console or in the Network tab, so read that first, and hitting the URL with curl -i separates "the server is down" from "the browser refused". Firefox words the same situation as NetworkError when attempting to fetch resource.

Q. How do I fix it?

curl -i https://api.example.com/data — before running it, check the explanation above for what this command discards.

Q. Which tool prints this?

chrome. It sits under JavaScript, and the message runs to 4 words.

Errors nearby