Skip to content
Latchkey

ESLint "Cannot read properties of undefined (reading 'getTokens')"

An ESLint rule called a SourceCode/context method (getTokens) that is undefined for the parser or ESLint version in use. This is a version-mismatch between ESLint, the parser (often @typescript-eslint/parser), and the plugins.

What this error means

Linting crashes with TypeError: Cannot read properties of undefined (reading 'getTokens') (or a similar SourceCode method), with a stack into a rule or the parser. It is deterministic - a dependency mismatch, not flake.

eslint output
TypeError: Cannot read properties of undefined (reading 'getTokens')
    at /app/node_modules/@typescript-eslint/parser/dist/parser.js:120:31
    at Linter._verifyWithoutProcessors (/app/node_modules/eslint/lib/linter/linter.js:...)

Common causes

Parser incompatible with the ESLint version

ESLint changed SourceCode/parser APIs across majors (notably ESLint 9). An outdated @typescript-eslint/parser or plugin calls a method the new ESLint moved or removed.

Mismatched/duplicate ESLint versions

A config or plugin pulls in a second ESLint copy, so a rule runs against a different ESLint instance than the parser expects.

How to fix it

Upgrade ESLint, parser, and plugins together

Align eslint, @typescript-eslint/parser, and @typescript-eslint/eslint-plugin to compatible versions.

Terminal
npm install -D eslint@latest \
  @typescript-eslint/parser@latest @typescript-eslint/eslint-plugin@latest
npm ls eslint   # confirm a single eslint version

Deduplicate ESLint

  1. Run npm ls eslint to find every ESLint version in the tree.
  2. Align peers so there is one ESLint copy (dedupe, or pin via overrides).
  3. Reinstall from a clean lockfile so the resolved tree is reproducible.

How to prevent it

  • Upgrade ESLint and its parser/plugins as a set, not piecemeal.
  • Keep a single ESLint version in the tree (npm ls eslint).
  • Check the parser/plugin's supported ESLint range before bumping.

Frequently asked questions

What causes ""undefined (reading 'getTokens')""?
ESLint changed SourceCode/parser APIs across majors (notably ESLint 9). An outdated @typescript-eslint/parser or plugin calls a method the new ESLint moved or removed.
How do I fix "undefined (reading 'getTokens')"?
Align eslint, @typescript-eslint/parser, and @typescript-eslint/eslint-plugin to compatible versions.

Related guides

References

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