The Prompt BakeryTemplates and prompts

Fix · Node, npm and build

Unexpected token '<' in JSON (I got a web page instead of data)

What you may see

  • fetch or JSON.parse fails with Unexpected token <
  • It says "is not valid JSON"

Most likely cause

The address answered with an HTML page (often an error or a login page) instead of JSON, or with nothing at all.

Check first (about two minutes)

  1. Open the same address in a browser tab: do you see JSON or a web page?
  2. In the network tab, read the status code of that request.

The fix prompt

What you type here never leaves your browser. The search runs on this page, and nothing is sent to a server or to an AI.

Kept only in this browser, on this device. Keys and passwords are removed before anything is saved.

Prompt language

Paste it into Claude, ChatGPT, Gemini or Cursor, then follow what it says.

After you tried it, did it work?

Steps

  1. Show the fetch call and its address. Check the address is right (a missing /api, a wrong domain, http versus https).
  2. Read the real status and body first (response.status and response.text()) before parsing.
  3. Fix the cause (wrong address, a 404, a redirect to login, a crash in the route) and add a clear error message for non-200 answers.

Do not do this

  • Do not guess: read the body of the response.
  • Do not wrap the parse in an empty try/catch.

Related

Try another entry

How can we help?

What do you need?
Your email, so we can reply (optional)Only enter your own email. We reply there.