Unexpected token < 🟨 JavaScript

SyntaxError: Unexpected token '<' (HTML served instead of JavaScript)

The browser loaded a .js file but received HTML (an error page or the SPA index.html).

Seen on: JavaScript

Meaning

The first character of an HTML document is <. Wrong script paths, missing build files and SPA fallbacks returning index.html for every URL cause it.

Common causes

  • Script path wrong (relative vs absolute)
  • Build file missing → server returns index.html
  • Deployed under a sub-path without updating base path
  • JSX served without compilation

⚡ Quick fix

  1. Open the script URL directly in the browser
  2. Fix the base/public path in the bundler config
  3. Ensure the build output is deployed

Detailed fix by platform

JavaScript

  1. Vite: set base: '/app/' when serving from a sub-folder

How to diagnose

  1. URL — What does the script URL actually return?
  2. Build — Do the files exist on the server?

🧠 Still stuck? Analyze your error

Paste the full message, response headers or stack trace — we'll detect the platform and point to the most likely cause.