Skip to content
Latchkey

ESLint "Parsing error: The keyword 'import' is reserved"

ESLint's default parser is configured for an older ECMAScript version or for scripts, not modules, so import/export is unexpected. The code is valid ESM; the parser options just do not allow it.

What this error means

ESLint fails with Parsing error: The keyword 'import' is reserved or Unexpected token import on a file that uses import/export. The code runs fine; only the linter rejects it.

eslint
/app/src/index.js
  1:1  error  Parsing error: The keyword 'import' is reserved
> 1 | import { foo } from './foo'
    | ^

Common causes

ecmaVersion too low

A parserOptions.ecmaVersion below 2015 (or unset on an old config) means the parser does not recognize ES module syntax.

sourceType not set to module

Without sourceType: 'module' (legacy config) the parser treats files as scripts, where top-level import is illegal. Flat config defaults to module, but custom parsers may not.

How to fix it

Set ecmaVersion and sourceType

Configure the parser for modern ES modules.

eslint config
// .eslintrc.json
{ "parserOptions": { "ecmaVersion": "latest", "sourceType": "module" } }
// flat config (eslint.config.js):
// languageOptions: { ecmaVersion: 'latest', sourceType: 'module' }

Use a parser that supports your syntax

  1. For TypeScript/JSX, set parser: '@typescript-eslint/parser' (or the appropriate parser).
  2. Add parserOptions.ecmaFeatures.jsx: true when linting JSX.
  3. Confirm the file extension is covered by the config that sets these options.

How to prevent it

  • Set ecmaVersion: "latest" and sourceType: "module" for ESM projects.
  • Use the right parser for TypeScript/JSX syntax.
  • Keep one parser config across local and CI so parsing matches.

Frequently asked questions

What causes ""keyword 'import' is reserved""?
A parserOptions.ecmaVersion below 2015 (or unset on an old config) means the parser does not recognize ES module syntax.
How do I fix "keyword 'import' is reserved"?
Configure the parser for modern ES modules.

Related guides

References

Latchkey auto-heals failures like this one - detected, fixed, and retried without you. Start free → 30-day trial · No credit card