[Support Guide] Why do I see “Uncaught SyntaxError: Unexpected token <” errors? How can I use chunking or versioning for my assets at Netlify?

The error Uncaught SyntaxError: Unexpected token < is most commonly caused by your site’s code referring to an asset that is no longer available. Most commonly, this is due to a filename change in assets generated during your build. The same situation happens if you use versioned or chunked javascript where the filename changes with every deploy.

Let’s look at an example:

A file that was named /assets/main-123abc.js would change to /assets/main-456def.js – where there is a variable hash included in the filename. Your build tools may be doing that for you automatically even if you don’t intend for them to be.

In many cases, this is not a needed pattern on Netlify, since it is used for cache-busting. You can read more about how we handle caching in this thread and also in this article about our CDN’s caching.

The primary pattern where this makes sense even on our CDN is with javascript code-splitting, or with versioning. If disabling those hashes are not an option, there are a few workarounds such as the ones mentioned in this spectrum thread that may help you create a successful implementation.

If you are still experiencing problems and none of these solutions work, please start a new topic where you describe your specific situation, and mention that you have read this post already, so you don’t get sent back here :slight_smile:

1 Like