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.
/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.
// .eslintrc.json
{ "parserOptions": { "ecmaVersion": "latest", "sourceType": "module" } }
// flat config (eslint.config.js):
// languageOptions: { ecmaVersion: 'latest', sourceType: 'module' }Use a parser that supports your syntax
- For TypeScript/JSX, set
parser: '@typescript-eslint/parser'(or the appropriate parser). - Add
parserOptions.ecmaFeatures.jsx: truewhen linting JSX. - Confirm the file extension is covered by the config that sets these options.
How to prevent it
- Set
ecmaVersion: "latest"andsourceType: "module"for ESM projects. - Use the right parser for TypeScript/JSX syntax.
- Keep one parser config across local and CI so parsing matches.