ESLint cannot find the tsconfig.json you pointed it at
Parsing 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.
Fix it fast
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.json2Match what you see, then jump to its fix
- 1
ESLint 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
The 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
You 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
- 1
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: __dirname3Verify
Run ESLint from the repo root and from a sub-folder.
npx eslint src
cd src && npx eslint .Confirmed by typescript-eslint.io
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*.json2Fix
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.tsConfirmed by typescript-eslint.io
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.tsConfirmed by typescript-eslint.io
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:
- TaxiDexMy own multi-tenant taxi dispatch SaaS: API, dispatcher portal, driver and passenger apps, and the servers underneath.
- QistLockA NestJS and React SaaS driving an Android Device Owner agent that locks financed phones when payments lapse.
- WorkforceA field app, an admin console and a self-hosted Node.js server for push and reconciliation.
Related fixes
Web apps
ESLint was configured to run using parserOptions.project, but the file is not in the TSConfig
However, that TSConfig does not include this file
Type-aware linting needs every linted file to belong to a TypeScript project.
4 causes, each with a fixBack end
TypeScript cannot find '@angular/platform-browser' in an Angular project
Cannot find module '@angular/platform-browser' or its corresponding type declarations.
TS2307 means TypeScript could not turn the import into a file.
3 causes, each with a fixBack end
Angular build fails with TS2707 or "has no exported member" after installing a library
Module '"@angular/core"' has no exported member
These errors mean a library was compiled by a newer Angular than your app uses.
3 causes, each with a fixBack 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 fixBack end
TypeScript cannot find module '@nestjs/core' or its type declarations
error TS2307: Cannot find module '@nestjs/common' or its corresponding type declarations.
TS2307 means TypeScript searched node_modules and found neither the package nor its types.
3 causes, each with a fixBack 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