← All errors · Lovable
Unexpected token '<', "<!DOCTYPE "... is not valid JSON
Exact error
SyntaxError: Unexpected token '<', "<!DOCTYPE "... is not valid JSON
What it means
Your code called response.json(), but the server returned an HTML page (often a 404 page or index.html) instead of JSON.
Likely causes
- Wrong API URL or path, so the host serves an HTML 404 or the SPA fallback.
- The API route doesn't exist in production (e.g. a static host with no backend).
- Server error page returned as HTML.
How to fix it
Check the Network tab: open the request and see its URL, status and HTML response.
Check response.ok before parsing:
const res = await fetch(url); if (!res.ok) throw new Error(`${res.status}: ${await res.text()}`); const data = await res.json();Fix the URL / base URL env var, and make sure an SPA rewrite isn't catching your /api routes.
Related errors
Get new fixes weekly
No spam. Unsubscribe anytime. Privacy