292

The error Parsing error: Cannot read file '.../tsconfig.json'.eslint shows in all .ts files in the src folder including index.ts.

I have no idea how to set up configs. The issue just shows a red line and makes the file red. However, everything compiles and run fine. The entire Node project was created using the firebase CLI.

tsconfig.json file:

{
  "compilerOptions": {
    "module": "commonjs",
    "noImplicitReturns": true,
    "noUnusedLocals": true,
    "outDir": "lib",
    "sourceMap": true,
    "strict": true,
    "target": "es2017"
  },
  "compileOnSave": true,
  "include": [
    "src"
  ]
}

.eslintrc.js file:

module.exports = {
  env: {
    browser: true,
    es6: true,
    node: true,
  },
  extends: [
    "plugin:import/errors",
    "plugin:import/warnings",
    "plugin:import/typescript",
  ],
  parser: "@typescript-eslint/parser",
  parserOptions: {
    project: "tsconfig.json",
    sourceType: "module",
  },
  plugins: [
    "@typescript-eslint",
    "import",
  ],
  rules: {
    "@typescript-eslint/adjacent-overload-signatures": "error",
    "@typescript-eslint/no-empty-function": "error",
    "@typescript-eslint/no-empty-interface": "warn",
    "@typescript-eslint/no-floating-promises": "error",
    "@typescript-eslint/no-namespace": "error",
    "@typescript-eslint/no-unnecessary-type-assertion": "error",
    "@typescript-eslint/prefer-for-of": "warn",
    "@typescript-eslint/triple-slash-reference": "error",
    "@typescript-eslint/unified-signatures": "warn",
    "comma-dangle": "warn",
    "constructor-super": "error",
    eqeqeq: ["warn", "always"],
    "import/no-deprecated": "warn",
    "import/no-extraneous-dependencies": "error",
    "import/no-unassigned-import": "warn",
    "no-cond-assign": "error",
    "no-duplicate-case": "error",
    "no-duplicate-imports": "error",
    "no-empty": [
      "error",
      {
        allowEmptyCatch: true,
      },
    ],
    "no-invalid-this": "error",
    "no-new-wrappers": "error",
    "no-param-reassign": "error",
    "no-redeclare": "error",
    "no-sequences": "error",
    "no-shadow": [
      "error",
      {
        hoist: "all",
      },
    ],
    "no-throw-literal": "error",
    "no-unsafe-finally": "error",
    "no-unused-labels": "error",
    "no-var": "warn",
    "no-void": "error",
    "prefer-const": "warn",
  },
  settings: {
    jsdoc: {
      tagNamePreference: {
        returns: "return",
      },
    },
  },
};

I had tried restarting VScode, clearing the cache, and all to no avail. I am guessing I need to change some of the paths but I am not very good at changing the config files so I don't want to accidentally break the entire project.

16 Answers 16

494

2025 Update: typescript-eslint v8 has stabilised the projectService option, which is now recommended over project. See the Typed Linting with Project Service announcement for further details.


By default, the projects (in parserOptions) are resolved relative to the current working directory. If you run eslint in a different working directory to the folder containing tsconfig.json, @typescript-eslint/parser will not be able to locate the file.

To fix this, you can set tsconfigRootDir to __dirname, which would make the parser resolve the project configuration relative to .eslintrc.js.

Legacy config:

module.exports = {
  // ...
  parserOptions: {
    project: "tsconfig.json",
    tsconfigRootDir: __dirname,
    sourceType: "module",
  },
  // ...
}

ESLint’s v9 flat config, eslint.config.mjs (although see the update above regarding projectService):

import tseslint from 'typescript-eslint'

export default tseslint.config(
  // ...
  {
    languageOptions: {
      parserOptions: {
        project: 'tsconfig.json',
        tsconfigRootDir: import.meta.dirname,
      },
    },
  },
);


If you’re having some trouble with

/path/to/.eslintrc.js
  0:0  error  Parsing error: "parserOptions.project" has been set for @typescript-eslint/parser.
The file does not match your project config: .eslintrc.js.
The file must be included in at least one of the projects provided

see the official troubleshooting section on this or this question.

Sign up to request clarification or add additional context in comments.

11 Comments

It fixed all file warnings but the .eslint is still giving a new issue: Parsing error: "parserOptions.project" has been set for @typescript-eslint/parser. The file does not match your project config: .eslintrc.js. The file must be included in at least one of the projects provided
The module.exports code is located in the submodule's eslintrc.js file for anyone wondering.
Is there a way to do this if you have an .eslintrc.yml file?
how would this work in .json?
|
142

A VSCode-specific approach, that worked for me was to create a .vscode folder in the root project directory and add the following property to the settings.json file inside it:

{
  "eslint.workingDirectories": [
    "src"
  ]
}

The "src" could be any directory, which should be in eslint's scope.

5 Comments

If you have the following directories in your root folder: "backend" and "frontend", this will work: "eslint.workingDirectories": [ "backend", "frontend" ]
For Firebase Cloud Functions, use "eslint.workingDirectories": ["functions"]
it worked for my firebase functions! thank you so much!
I had the similar issue and this worked for me perfectly!
this solved my issue for firebase functions
93

For those using Angular and eslintrc.json, add the 2 stars to the project node like this:

"overrides": [
  {
    "files": ["*.ts"],
    "parserOptions": {
      "project": ["**/tsconfig.json"]
    }
  }
]

4 Comments

Can someone explain why the 2 astres needed?
first for name, second for type
fix my problem too. thanks
This gets eslint working but now many angular components have a red squiggly on line 1 complaining that elsint cannot read tsconfig.json. It's looking one level above where the file is located - in ProjectName rather than ProjectName/ClientApp. I cannot see where that path is coming from
77

Update your eslintrc.json file with the following line:

"project": "PROJECT_NAME/tsconfig.json"

with PROJECT_NAME being the name of your project (not a macro).

4 Comments

This is a simple and straightforward solution!!!
This worked for me using Ionic 6
I guess this would've worked for me if my project folder was at the root of my multi-project solution. But I needed to use "PATH_TO_PROJECT/tsconfig.json".
Do you have a link to docs? I'm getting Error: ESLint configuration in ..\..\..\.eslintrc.json is invalid: - Unexpected top-level property "project"." and couldn't find it (quickly?) in eslint.org/docs/latest
13

Another approach is if you happened to open the Workspace folder one level above the Project (as was in my case), just start a new Workspace with the ACTUAL project folder. That solved my Eslint error.

1 Comment

This worked for me as well, as I was using some test files that I was keeping stored in the projects parent directory after cloning a fresh repo. I imagine that setting some of these config options would work if we provided the project's parent directory in the config, but this way we don't have to dance around git commands. Cheers.
13

I solved it by adding @typescript-eslint/parser to the extends:

enter image description here

3 Comments

Please post your code directly to the post, no need of adding extra extra URLs that can become invalid in the future.
Bro screenshotted it
For me this just masks the problem by crashing eslint.
10

A VSCode specific approach that worked for me was adding the following to settings.json

"eslint.workingDirectories": [
    {
      "mode": "auto"
    }
  ]

Comments

8

I suddenly started seeing this error using vscode. Restarting vscode has resolved my issue

Comments

3

If you get the following error message in a multi-module project in IntelliJ (e.g. a folder containing several backend services as well as a frontend module), IntelliJ might not be able to tell what to do.

In my case I got the following error on top of a .ts-file: enter image description here

To fix this, I have clicked on "ESLint settings..." and picked "Manual ESLint configuration" enter image description here

Then I entered the path to the frontend module root folder in "Working directories:" and picked the correct path to eslint in "ESLint package" (which - in my case - was in <frontend-module-root>/node_modules/eslint).

This way I still get eslint to work and do not have to change any project-related configuration at all (it works from frontend module root folder in CLI already).

Comments

3

What fixed this for me is to simply navigate into the project directory containing my tsconfig.json, and that it was able to locate the file.

Otherwise, I liked @dheeraj9499's answer that you can modify your .eslintrc.json "project" array within "parserOptions" and locate where your tsconfig.json is located from within the current directory. So something like the following was able to find tsconfig.json in the correct directory:

"parserOptions": {
  "project": [
    "code/eMOS/Scripts/tsconfig.json",
    "code/eMOS/Scripts/tsconfig.spec.json"
  ],
 }

Comments

3

For those who have this problem with ionic framework do the Next: open .eslintrc.json and verify

“project”: [“tsconfig.json”, “the-parent-folder/tsconfig.json”],

Change the parent folder with the folder that contains your project and say Good bye to that annoying error♥

1 Comment

This 1.) fixes the error in the source code, and 2.) allows eslint to run properly on your project. This should be the accepted answer. (I'm running Stencil.js, but I think the project type is probably irrelevant.)
2

Parsing error: Cannot read file 'd:\test\testproject\tsconfig.app.eslint.json'.eslint One of the major issues I faced here because of the way the project folder is opened in vs code.

assume the folder structure is d:\test\testproject where 'testproject' is the angular project you are using.

if you are opening the test folder in vs code then navigating to testproject as below

D:\test>
D:\test>cd testproject
D:\test\testproject> 

Doing this will create 2 settings.json files, one for the main opened folder and one for the child folder which in turn doesn't allow the settings to be applied properly.

So always opening the project folder directly in the vscode would help overcoming the issue, when all the dependencies are mentioned properly in eslintrc.json and tsconfig.json files would help in solving the issue.

Comments

2

I had the same error in VS with TypeScript Analyzer (ESLint, Prettier) extension installed. Setting these values resolved the issue:

  • parserOptions.project = true
  • parserOptions.tsconfigRootDir = __dirname

Fixed Config

.eslintrc.js file (part with changed values):

  ...
  "parserOptions": {
    "sourceType": "module",
    "project": true,
    "tsconfigRootDir": "__dirname"
  },
  ...

Explanation

Even though main purpose of parserOptions.project = true is to resolve another problem ("improve the configuration and performance for typed linting") it also fixes issue from above.

Here are some details taken from article Relative TSConfig Projects with parserOptions.project = true about how it works:

As of typescript-eslint 5.52.0, we now support providing true for parserOptions.project:

module.exports = {
  // ...
  parserOptions: {
    project: true,
    tsconfigRootDir: __dirname,
  },
  // ...
};

Doing so indicates that each source file being linted should use type information based on the nearest tsconfig.json in its directory. For each file, @typescript-eslint/parser will check that file's directory, then the parent directory, and so on - until a tsconfig.json file is found.

💡 TIP

We recommend setting the tsconfigRootDir ESLint config to the project's root directory (most commonly, __dirname). That way, if you accidentally delete or rename the root tsconfig.json file, @typescript-eslint/parser won't search parent directories for higher tsconfig.json files.

Comments

1

I got this error in Visual Studio Code when working on a typescript project via WSL 2 on Windows 10.

It was fixed by installing the Remote - WSL extension in VS Code.

The files were hosted in my \wsl$\Ubuntu\home<user>\ location. The error message specified the correct file location, and VS Code could open the file.

The above fixes using the root directory and parser options did not help.

Comments

1

It works for me

"parserOptions": {
  "project": ["<YourProjectName>/tsconfig.json"],
}

1 Comment

For me, this removed the error in the source code, but running eslint then doesn't work.
0

in my case, I have mono repo setup so eslint was pointing to root tsconfig which was causing the problem. Then I changed .eslintrc.json configuration in backend folder which solved my problem. Following is my configuration:

 {
  "extends": [
    "plugin:adonis/typescriptApp",
    "prettier",
    "eslint:recommended",
    "plugin:@typescript-eslint/recommended"
  ],
  "plugins": ["prettier", "@typescript-eslint"],
  "parser": "@typescript-eslint/parser",
  "parserOptions": {
    "project": "./backend/tsconfig.json",
    "tsconfigRootDir": "__dirname",
    "ecmaVersion": 2020,
    "sourceType": "module"
  },
  "rules": {
    "prettier/prettier": "error",
    "@typescript-eslint/explicit-module-boundary-types": "off",
    "@typescript-eslint/no-unused-vars": "warn",
    "@typescript-eslint/no-explicit-any": "off",
    "no-console": "warn"
  },
  "env": {
    "node": true,
    "es6": true
  }
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.