SyntaxError: Unexpected token '<'
The JavaScript parser hit something it didn’t expect.
Fix 1: HTML in a JS file
SyntaxError: Unexpected token '<'
You’re loading an HTML page instead of a JS file. Check your script src:
<!-- ❌ Wrong path — server returns HTML 404 page -->
<script src="/scrpts/app.js"></script>
<!-- ✅ Correct path -->
<script src="/scripts/app.js"></script>
Fix 2: JSON parse error
// ❌ Response is HTML, not JSON
const data = JSON.parse('<html>...');
// ✅ Check the response first
const res = await fetch('/api/data');
if (!res.ok) throw new Error(`HTTP ${res.status}`);
const data = await res.json();
Fix 3: Missing comma or bracket
// ❌ Missing comma
const obj = { a: 1 b: 2 };
// ✅
const obj = { a: 1, b: 2 };