The easiest way to solve the error is to add the files in which you get it to your . eslintignore file, which should be located in the root directory of your project, right next to . eslintrc. js .
parserOptions. This option allows you to request that when the project setting is specified, files will be allowed when not included in the projects defined by the provided tsconfig. json files. Using this option will incur significant performance costs. This option is primarily included for backwards-compatibility.
@typescript-eslint/parser - A parser that converts TypeScript into an ESTree-compatible form so it can be used in ESLint.
The problem happens for one of the reasons below:
parserOptions.project
;parserOptions.project
, didn't specify createDefaultProgram
(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
Add one line in ".eslintignore":
.eslintrc.js
You need to add that file to your tsconfig include
array.
See typescript-eslint/typescript-eslint#967 for more details.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With