Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4072 pages
Next.js and React

ESLint cannot parse your JSX or modern syntax

ErrorParsing 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.

  • Applies to ESLint 9, eslint-plugin-react 7, Node.js 22
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Fix it fast

  1. 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.jsx
  2. 2Match what you see, then jump to its fix

    1. 1Parsing error: Unexpected token < pointing at the first JSX tagJSX parsing is not switched onFix
    2. 2Parsing error on import or export lines, or on newer syntax such as optional chainingAn old ecmaVersion or script mode is setFix
    3. 3JSX files fail while .js files pass, or the rule block never applies to .jsxThe config object does not match the file extensionFix

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.js

2Fix

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.jsx

Confirmed by eslint.org

Did this fix it?

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.js

2Fix

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.js

Confirmed by eslint.org

Did this fix it?

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" | head

2Fix

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 src

Confirmed by eslint.org

Did this fix it?

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:

Related fixes

Next step

Want this handled for good?

I look after servers, apps and releases end to end. Tell me what keeps breaking.