ESLint cannot parse your JSX or modern syntax
Parsing error: Unexpected token <Short answer
ESLint's built-in parser reads JSX only when ecmaFeatures.jsx is on, and it only lints file types your config lists. A parse error on the first < or import means the config turns JSX off, sets an old ecmaVersion or script mode, or does not cover that file extension. Fix the config, not the code.
Fix it fast
1Find out which cause you have
Ask ESLint which config applies to the file that fails. If the output has no jsx option, the parser is reading plain JavaScript.
npx eslint --print-config src/App.jsx2Match what you see, then jump to its fix
- 1
Parsing error: Unexpected token < pointing at the first JSX tagJSX parsing is not switched onFix - 2
Parsing error on import or export lines, or on newer syntax such as optional chainingAn old ecmaVersion or script mode is setFix - 3
JSX files fail while .js files pass, or the rule block never applies to .jsxThe config object does not match the file extensionFix
- 1
What does the error look like?
Parsing error: Unexpected token <Parsing error: Unexpected token =Parsing error: 'import' and 'export' may appear only with 'sourceType: module'
Cause 1 of 3
JSX parsing is not switched on
1Check
The default parser handles JSX only when ecmaFeatures.jsx is true. Search the config for it.
grep -n "jsx" eslint.config.js2Fix
Turn it on under languageOptions.parserOptions. This only teaches the parser the syntax; for React rules add a React plugin such as eslint-plugin-react.
// eslint.config.js
import { defineConfig } from "eslint/config";
export default defineConfig([
{
files: ["**/*.js", "**/*.jsx"],
languageOptions: {
parserOptions: { ecmaFeatures: { jsx: true } },
},
},
]);3Verify
Run ESLint on the file that failed.
npx eslint src/App.jsxConfirmed by eslint.org
Cause 2 of 3
An old ecmaVersion or script mode is set
1Check
The defaults are ecmaVersion latest and sourceType module. A config that overrides them with an old version or script breaks modern files.
grep -nE "ecmaVersion|sourceType" eslint.config.js2Fix
Delete the override, or set the defaults back. The ESLint docs say to put these two options in languageOptions rather than parserOptions.
languageOptions: {
ecmaVersion: "latest",
sourceType: "module",
},3Verify
Lint a file that contains an import statement.
npx eslint src/index.jsConfirmed by eslint.org
Cause 3 of 3
The config object does not match the file extension
1Check
By default ESLint lints only .js, .cjs and .mjs. Settings placed in an object with a files list that omits .jsx never reach those files.
npx eslint --debug src/App.jsx 2>&1 | grep -i "config" | head2Fix
Add the extension to the files patterns of the object that holds your language options.
{
files: ["**/*.js", "**/*.cjs", "**/*.mjs", "**/*.jsx"],
languageOptions: { parserOptions: { ecmaFeatures: { jsx: true } } },
}3Verify
Run the linter across the project; the .jsx files are checked.
npx eslint srcConfirmed by eslint.org
How do I stop it coming back?
- Keep one eslint.config.js at the project root and review it when you add a new file extension.
- Leave ecmaVersion and sourceType at their defaults unless you target an old runtime.
- Run the linter in CI so a broken config fails a build instead of an editor.
- Use --print-config when a rule seems not to apply.
Sources
How was this page made?
I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.
Which stack is behind this page?
Projects of mine built on the same technologies:
- TaxiDexMy own multi-tenant taxi dispatch SaaS: API, dispatcher portal, driver and passenger apps, and the servers underneath.
- QistLockA NestJS and React SaaS driving an Android Device Owner agent that locks financed phones when payments lapse.
- WorkforceA field app, an admin console and a self-hosted Node.js server for push and reconciliation.
Related fixes
Web apps
React shows Attempted import error when importing a component or function
Attempted import error:
The build found the file but not the name you asked for.
2 causes, each with a fixWeb apps
AxiosError Network Error with code ERR_NETWORK in a React app
Network Error
ERR_NETWORK means the request produced no readable response.
4 causes, each with a fixWeb apps
Axios get works with a URL string but ignores the object passed as the second argument
The server log shows a GET with no query string
axios.get takes a URL and an optional config object.
3 causes, each with a fixWeb apps
Can't resolve '../axios' in a React project
Module not found: Error: Can't resolve '../axios'
A path that starts with ./ or ../ is a file path, not the axios package.
3 causes, each with a fixWeb apps
Axios returns 401 from a React app but the login works elsewhere
Error: Request failed with status code 401
A 401 means the server received the request without valid credentials.
3 causes, each with a fixWeb apps
An axios call never finishes when the API server stops answering
code: 'ECONNABORTED'
Axios has no timeout unless you give it one: the default is 0, which means wait forever.
3 causes, each with a fix