"parserOptions.project" has been set for @typescript-eslint/parser
The problem happens for one of the reasons below:
- You're using a rule which require type information and didn't specifya
parserOptions.project
; - You specified
parserOptions.project
, didn't specifycreateDefaultProgram
(it will be removed in a future version), and you're linting files not included in the project (e.g.babel.config.js
,metro.config.js
)
As from the TypeScript ESLint Parser docs:
parserOptions.project
This option allows you to provide a path to your project's
tsconfig.json
. This setting is required if you want to use rules which require type information.(...)
Note that if this setting is specified and
createDefaultProgram
is not, you must only lint files that are included in the projects as defined by the providedtsconfig.json
files. If your existing configuration does not include all of the files you would like to lint, you can create a separatetsconfig.eslint.json
.
To solve it, update your ESLint config to the following:
{ // ... overrides: [ { files: ['*.ts', '*.tsx'], // Your TypeScript files extension parserOptions: { project: ['./tsconfig.json'], // Specify it only for TypeScript files }, } ], parser: '@typescript-eslint/parser', // ...}
You can create a separate TypeScript config file (tsconfig.eslint.json
) intended for eslint
configuration. That file extends tsconfig
configuration and setups include
key for files that have to be linted.
.eslint.js
:
// ...parserOptions: { // ... project: "./tsconfig.eslint.json", // ...},// ...
tsconfig.eslint.json
:
{ "extends": "./tsconfig.json", "include": [ // ... "babel.config.js" ]}
Or if you want to ignore it, you can put it into .eslintignore
.
.eslintignore
:
// ...babel.config.js
You need to add that file to your tsconfig include
array.See typescript-eslint/typescript-eslint#967 for more details.