mk12
mk12

Reputation: 26404

Syntax Error: "Unexpected token <" in Web Console

Why am I getting this error in the web console? It just says "line 1, col 1" with that error. When I click the link, I'm brought to the source of my homepage, and it's telling me it didn't expect the < in the doctype!

(For SEO: opening angle bracket, less than sign)

Upvotes: 1

Views: 4997

Answers (3)

Geoffrey Hale
Geoffrey Hale

Reputation: 11448

TL;DR

check bad path to file.js

Upvotes: 2

Cijo V J
Cijo V J

Reputation: 261

I don't know if this could help anyone as this is an old post. If you are using any Text Editor like Sub Lime there is great chance that use selected the tag from intellisense and the opening tag "<" that you first typed is still there.Check if you could find any.In this case review your DOCTYPE tag in the beginning of HTML

Upvotes: 0

mk12
mk12

Reputation: 26404

In my case, I was using a javascript library and loading a theme file as part of the configuration. I misspelled the path to the file, which is what caused all of this. Why didn't it give me a better error message? Because I have my website set up to redirect all 404s to the homepage. So it tried to interpret my homepage HTML as the js theme file.

If you get a strange error like this, there's a good chance that you just made a typo.

If you redirect 404s to the homepage, it would probably be a good idea to disable it during development.

Upvotes: 1

Related Questions