svelte: Uncaught SyntaxError: Unexpected token <

Got this error in console after running npm run dev

Logs Uncaught SyntaxError: Unexpected token <

To Reproduce "svelte": "^3.0.0"

Node js version v12.4.0

OS and Browser Ubuntu 19.04 Chrome: Version 75.0.3770.142 (Official Build) (64-bit)

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Reactions: 6
  • Comments: 45 (15 by maintainers)

Most upvoted comments

Had this same issue. Some sort of caching issue I think because when I opened in an incognito window everything just worked. Looking into a solution, assuming it has something to do with rollup?

Update: Setting the cache to disabled in the browser network tab worked for me. Not a long term solution, but works for now. cc @antony @php7webmob

Screen Shot 2019-08-16 at 1 13 19 PM

I know the issue is closed, but I thought I’d shed a little light on this as it was discussed on Discord.

The problem occurs because sirv public --single decides to send index.html for any route/resource that doesn’t exist in the public directory. You’ll know right away that you have a problem when you are requesting, say, an image and you get back 200 text/html response instead of a 404.

The browser will try to parse the index.html content as though it were an image (or script in the case of this bug) and barf out. Even worse is that the cache is now polluted with garbage data for that URL and the only way to fix it is to clear the cache or disable the cache completely.

Hope that helps… I know it drove me nuts for a while!

Ctrl + Shift + R y listo

This issue happened to me many times. Every time, the reasons were different. Would be good to find a way to print more specific and less general info. As for now, it’s a blind fix.

Seems to happen when the url has more than one level in its path.

Working -> /some Not working -> /some/page

Edit

Solution:

So, having something like <script src="bundle.js"> will resolve to /blog/bundle.js when trying to load it from an Article route. You need to use <script src="/bundle.js"> (and same for styles).

@jaison10 try to load your js files directly from the server - you may find you are being served up HTML instead of Javascript