Running Karma tests gives me SyntaxError Invalid or unexpected token

July 07, 2022

Help, help, running karma tests gives me SyntaxError Invalid or unexpected token but the file seems to be OK (you can perhaps still hear me screaming).

The clue to problem might be a small hint at the beginnig of the error you might see in the cmd line :

karma error cmd line

Do you see the strange ?? on line 3?

Yep, that was my case - BOM at the beginning of karma.conf.js file and the funny part - it is even discuraged to use it, but my editor somehow managed to save it to karma file. Could this be reported in a nicer way? Yep, it could. But it is not.

If interested you can find more on UTF with BOM here https://stackoverflow.com/questions/2223882/whats-the-difference-between-utf-8-and-utf-8-without-bom

Hope this helps.


Profile picture

Written by Dušan Roštár - the "mr edge case" guy
my twitter : rostacik, my linkedin : rostar
Reach me at dusan at thisdomain.net