eslint · Build and types
The message
Parsing error: Unexpected token
What it means
ESLint stopped while reading the syntax, before any rule was applied to the file. Far more often than actually broken code, this means the parser does not know that syntax — a TypeScript file read by the default parser, JSX that was never enabled, or decorators and very new syntax handed to an old parser. Running npx eslint --print-config app.ts against that exact file prints which parser and parserOptions really apply, so start there instead of guessing. TypeScript needs @typescript-eslint/parser, and if the file should not be linted at all, listing it under ignores is the right answer.
The fix
npx eslint --print-config app.ts- Printed by
- eslint
- Build and types
- 10
Build errors are a tool refusing before anything runs, so they break nothing at the moment they appear — but they do ask two questions: will you fix the type or the path to match the real shape, or will you push that one line through with an as any or a suppression comment — and it is here that the things which are only true on your own machine, letter case, extensions and environment variables, show themselves for the first time.
Reading an error message
- Read from the first line down. The lower you go the more it is about the tool’s internals; the cause is usually at the top.
- If there is a file and a line number, start there — not the top stack frame, but the topmost line that names a file you wrote.
- Search the message verbatim, but strip your own paths and variable names first; those are what stop the search from matching.
- The same condition is worded differently across tool versions. If results look wrong, add the version number to the query.
- Before pasting a fix, check what it throws away. Some of these cannot be undone.
Common questions
Q. What does “Parsing error: Unexpected token” mean?
ESLint stopped while reading the syntax, before any rule was applied to the file. Far more often than actually broken code, this means the parser does not know that syntax — a TypeScript file read by the default parser, JSX that was never enabled, or decorators and very new syntax handed to an old parser. Running npx eslint --print-config app.ts against that exact file prints which parser and parserOptions really apply, so start there instead of guessing. TypeScript needs @typescript-eslint/parser, and if the file should not be linted at all, listing it under ignores is the right answer.
Q. How do I fix it?
npx eslint --print-config app.ts — before running it, check the explanation above for what this command discards.
Q. Which tool prints this?
eslint. It sits under Build and types, and the message runs to 4 words.