Parsing error: Cannot read file '.../tsconfig.json'.eslint
By default, the project
s (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
:
module.exports = {
// ...
parserOptions: {
project: "tsconfig.json",
tsconfigRootDir: __dirname,
sourceType: "module",
},
// ...
}
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 this question.
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.