← 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

How to fix it

  1. Check the Network tab: open the request and see its URL, status and HTML response.

  2. 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();
  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