Short answer
Go to the line and column in the error and retype the quotes and dashes on it by hand. Code pasted from a document, a chat app or a web page often brings curly quotes, long dashes or zero-width spaces with it. Search the file for any non-ASCII character with the regex [^\x00-\x7F] in your editor. Also look for a single- or double-quoted string that runs onto the next line: use a template literal for multi-line text.
Why the parser rejects the character, and the fix
01
Curly quotes or dashes pasted from a document
“There is an invalid character that the interpreter doesn't understand. You should either put it in a string literal or replace it with another character.” MDN, SyntaxError: illegal character
Word processors, Notion, Slack and many web pages turn straight quotes into curly ones and hyphens into longer dashes. In code those are not quotes or minus signs at all. Replace them with plain ASCII characters.
02
An invisible character
Zero-width spaces and similar invisible characters are invalid outside strings. Non-breaking spaces and a leading byte order mark are legal whitespace in JavaScript, but they can break other tools, so the search below lists them too. VS Code highlights many of them.
# list lines with non-ASCII characters (ripgrep) rg -n '[^\x00-\x7F]' src/03
A string broken across lines
Single- and double-quoted strings must end on the same line. A line break inside one leaves the quote open. Use a template literal, or join the lines with +.
const message = `Hello, your order has shipped.`;04
HTML or another file served as JavaScript
If a script URL returns an HTML page (often a 404 or index.html), the error is usually Unexpected token '<' rather than this one. Open the script URL in the browser to see what comes back.
Checked against the vendor’s docs on : MDN: SyntaxError: illegal character.
Rather hand it over?
Fixed scope, fixed price, paid upfront. The work happens in writing; no call needed.
- from $450App Fix TicketOne reproducible bug in an existing mobile or web app, diagnosed and fixed.See scope and start
- from $450AI-Built App RescueA Lovable, Bolt or Cursor app checked end to end in 3 days, then its worst problems fixed at a fixed price.No issues worth fixing, no charge. If the Launch Check finds nothing rated medium or higher, Simon refunds the full $450. You keep the report either way. This applies to the first 10 Launch Checks bought after October 30, 2026.See scope and start
Related: “SyntaxError: Unexpected identifier” · “Unexpected token < in JSON” · TypeError: “x is not a constructor”