How to fix Svelte error – Uncaught SyntaxError: Unexpected token <

If you are working in a Svelte project, you may have come across the following error while running the command npm run dev.

Uncaught SyntaxError: Unexpected token <

Thankfully, this relatively straightforward to address. To remedy this error, set the cache to disabled in your browser’s developer tools.

This commonly occurs when you have created a new instance of localhost for your project locally. The browser then fetches a previous reference to index.html and causes the error.

Gareth Dunne

Senior JavaScript Engineer and creator of JSdiaries. Passionate about the latest in web technologies and how it can provide value for my clients.