Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4072 pages
Node.js, PHP and APIs

ESLint cannot find the tsconfig.json you pointed it at

ErrorParsing error: Cannot read file '.../tsconfig.json'.

Short answer

The parser could not open the tsconfig named in parserOptions.project. A relative path is read from the folder ESLint was started in unless tsconfigRootDir is set, so running ESLint from another folder or an editor breaks it. Set tsconfigRootDir, correct the path, or switch to projectService.

  • Applies to typescript-eslint 8, ESLint 9, TypeScript 5, Node.js 22
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Fix it fast

  1. 1Find out which cause you have

    Read the full path in the error, then check whether that exact file exists. It often points into the wrong folder.

    ls -l /full/path/from/the/error/tsconfig.json
  2. 2Match what you see, then jump to its fix

    1. 1ESLint works from the repo root but fails from the editor or from inside a sub-folder, and the path in the error has the wrong parent.A relative project path is resolved from the wrong folderFix
    2. 2The file named in the error does not exist, for example tsconfig.eslint.json that was never created.The path or file name is wrongFix
    3. 3You did not set tsconfigRootDir and the config file is imported from another place, such as a shared config package.tsconfigRootDir picks the wrong folder on its ownFix

What does the error look like?

  • Parsing error: Cannot read file '.../tsconfig.json'.

Cause 1 of 3

A relative project path is resolved from the wrong folder

1Check

Relative paths in project are read from the current working directory when tsconfigRootDir is not set. Print where ESLint is being run from.

pwd
grep -n "project\|tsconfigRootDir" eslint.config.* .eslintrc.*

2Fix

Set tsconfigRootDir to the folder of the config file, so the path no longer depends on where ESLint starts.

// eslint.config.mjs
languageOptions: {
  parserOptions: {
    project: './tsconfig.json',
    tsconfigRootDir: import.meta.dirname,
  },
}
// .eslintrc.cjs (CommonJS): tsconfigRootDir: __dirname

3Verify

Run ESLint from the repo root and from a sub-folder.

npx eslint src
cd src && npx eslint .

Confirmed by typescript-eslint.io

Did this fix it?

Cause 2 of 3

The path or file name is wrong

1Check

Compare the path in parserOptions.project with the files in the repo.

ls tsconfig*.json

2Fix

Correct the path, or create the file you referenced. A glob also works, and a relative path is still read from tsconfigRootDir.

parserOptions: {
  project: ['./tsconfig.json', './packages/*/tsconfig.json'],
  tsconfigRootDir: import.meta.dirname,
}

3Verify

Run ESLint on one file from each package.

npx eslint packages/api/src/index.ts

Confirmed by typescript-eslint.io

Did this fix it?

Cause 3 of 3

tsconfigRootDir picks the wrong folder on its own

1Check

The parser guesses the root from the call stack, finding the nearest eslint.config file. A shared or wrapped config can fool it.

ls eslint.config.*

2Fix

Use projectService, which finds the nearest tsconfig.json for each file, and set tsconfigRootDir yourself.

parserOptions: {
  projectService: true,
  tsconfigRootDir: import.meta.dirname,
}

3Verify

Lint a file in a nested folder.

npx eslint src/deep/nested/file.ts

Confirmed by typescript-eslint.io

Did this fix it?

How do I stop it coming back?

  • Always set tsconfigRootDir when you use project or projectService with a relative path.
  • Prefer projectService over a hand-written list of tsconfig paths.
  • Lint from the repo root in CI, and make the editor use the same config.

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

Back end

cdk synth says --app is required

--app is required either in command-line, in cdk.json or in ~/.cdk.json

The CDK CLI needs a command that runs your app and finds it in three places: the --app option, cdk.json in the project folder, or cdk.json in your home folder.

3 causes, each with a fix

Back end

Mocha or Node cannot find ts-node/register

Error: Cannot find module 'ts-node/register'

Node resolves ts-node/register from your project's node_modules, so the package must be installed there, next to typescript.

2 causes, each with a fix

Next step

Want this handled for good?

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