← All errors · LovableLovable & Bolt app errors
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.
Prevent this next time
- Connect the project to GitHub so every AI edit is versioned and reversible.
- Run `npm run build` locally or in CI before deploying an exported project.
FAQ
What does "Unexpected token '<', "<!DOCTYPE "... is not valid JSON" mean?
Your code called response.json(), but the server returned an HTML page (often a 404 page or index.html) instead of JSON.
What usually causes it?
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 do I fix it?
1. Check the Network tab: open the request and see its URL, status and HTML response. 2. Check response.ok before parsing: 3. 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