# SyntaxError: “Invalid or unexpected token”

> SyntaxError: Invalid or unexpected token. Usually curly quotes pasted from a doc, a hidden character, or a string broken across lines. How to find it.

Canonical: https://app369.com/fix/invalid-or-unexpected-token/
Last updated: 2026-11-08

A script fails to load with SyntaxError: Invalid or unexpected token (Firefox: illegal character; Safari: Invalid character). The JavaScript parser met a character it does not accept at that spot. Very often the line looks correct, because the culprit is a character that looks like a normal quote or space.

**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**

1. 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**](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Errors/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.
2. 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/
```
3. 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.\`;
```
4. 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 November 8, 2026: [MDN: SyntaxError: illegal character](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Errors/Illegal_character).

## **Rather hand it over?**

Fixed scope, fixed price, paid upfront. The work happens in writing; no call needed.

- [from $450**App Fix Ticket**One reproducible bug in an existing mobile or web app, diagnosed and fixed.**See scope and start**](https://app369.com/fixed-price/flutter-firebase-bug-fix/)
- [from $450**AI-Built App Rescue**A 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**](https://app369.com/fixed-price/ai-app-rescue/)

Related: [**“SyntaxError: Unexpected identifier”**](https://app369.com/fix/unexpected-identifier/) · [**“Unexpected token < in JSON”**](https://app369.com/fix/unexpected-token-in-json/) · [**TypeError: “x is not a constructor”**](https://app369.com/fix/is-not-a-constructor/)

Questions

## **More on this error**

<details>

<summary>**The line looks perfectly normal. What now? **+</summary>

Delete the quotes, dashes and spaces on that line and type them again on your keyboard. If that fixes it, the original characters were look-alikes.

</details>

<details>

<summary>**How do I stop this happening again? **+</summary>

Paste code into your editor from a code block or a plain-text source, and run Prettier or ESLint on save so a bad character shows up as an error straight away.

</details>

<details>

<summary>**Can you fix it for me? **+</summary>

If one bug is the whole problem, the App Fix Ticket covers it: a written diagnosis first, then the fix. If the app has more going on, the Launch Check is a written check of the whole app. Each issue found is rated critical, high, medium or low, with where it is and how it was confirmed. 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.

</details>

A different error?

## **Describe it and get a written quote**

Send the error and what you were doing. You get a written scope, a fixed price and a timeline; Simon replies by email, usually within one business day.

[**Describe your problem **→](https://app369.com/contact/) [**All fixes**](https://app369.com/fix/)