Search code examples
typescripteslinttypescript-eslint

ESlint - This file does not match your project config


I have been getting the following two errors

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

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

My project which is supposed to be used as a library, contains an src and a tests folder.

src/index.ts is my entry file and src/loaders/index.ts is imported via node style module resolution, i.e. import * from './loaders'.

Here is my .eslintrc

{
  "parser": "@typescript-eslint/parser",
  "extends": [
    "eslint:recommended",
    "plugin:@typescript-eslint/recommended",
    "plugin:jest/style",
    "plugin:jest/recommended",
    "prettier"
  ],
  "plugins": ["@typescript-eslint"],
  "parserOptions": {
    "project": "./tsconfig.eslint.json"
  },
  "root": true,
  "rules": {
    ...
  }
}

and here are my tsconfigs tsconfig.json

{
  "compilerOptions": {
    "target": "es2020",
    "module": "commonjs",
    "allowJs": true,
    "checkJs": true,
    "sourceMap": true,
    "outDir": "./dist",
    "strict": true,
    "noImplicitAny": true,
    "moduleResolution": "node",
    "isolatedModules": true,
    "baseUrl": ".",
    "allowSyntheticDefaultImports": true,
    "esModuleInterop": true,
    "skipLibCheck": true,
    "forceConsistentCasingInFileNames": true,
    "resolveJsonModule": true
  },
  "include": ["src/**/*"]
}

and tsconfig.eslint.json

{
  "extends": "./tsconfig.json",
  "include": [
    "tests/**/*"
  ]
}

Solution

  • There's a handy FAQ in the TypeScript-ESLint docs about this

    https://typescript-eslint.io/docs/linting/troubleshooting/#i-get-errors-telling-me-the-file-must-be-included-in-at-least-one-of-the-projects-provided

    TL;DR - if you want to lint a file with type-information, then you HAVE to include it in a tsconfig provided via parserOptions.projects.

    Also worth noting that in a tsconfig file which extends another tsconfig file - includes is not merged with the extended config. Thus in your tsconfig.eslint.json you have only includes tests/**/*, and src/**/* is not included. Hence the error.