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.
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.
npm install -D eslint@latest \
@typescript-eslint/parser@latest @typescript-eslint/eslint-plugin@latest
npm ls eslint # confirm a single eslint versionDeduplicate ESLint
- Run
npm ls eslintto find every ESLint version in the tree. - Align peers so there is one ESLint copy (dedupe, or pin via overrides).
- 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.