I am getting the error: -
Parsing error: "parserOptions.project" has been set for u/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.
IDE - WebStorm 20.1.1
Project structure: -
node_modules
src
--- testfile.js
.eslintrc.js
.prettierrc.js
baseeslint.js
package.json
tsconfig.json
.eslintrc.js: -
module.exports = {
extends: ['./baseeslint'],
parserOptions: {
project: './tsconfig.json'
},
rules: {}
}
baseeslint.js: -
module.exports = {
parser: '@typescript-eslint/parser'
}
tsconfig.json: -
{
"include": [
"/src/**/*.ts",
"/src/**/*.tsx"
],
"exclude": ["node_modules"],
"compilerOptions": {
"outDir": "./lib",
"types": ["styled-components", "react", "@types/react-router-dom", "reactstrap"]
}
}
I have absolutely no idea why this is happening? I would assume it would ignore files in the root, especially with include specified in my tsconfg.json?
Any help would be greatly appreciated.
EDIT: -
My solution, should it help others...
I added the ignorePatterns configuration to my .eslintrc.js file: -
module.exports = {
extends: ["mycustom/eslint-config"],
parserOptions: {
project: './tsconfig.json'
},
ignorePatterns: ["/*.*"],
rules: {}
}
This can also be done via .eslintignore (see Anton Bessonov's response below).
Another thing relating to this which maybe of use to others here is the VScode config I used (I switched from WebStorm to VSCode after posting the original question). I am a big fan of running eslint fix on save but I do not want it attempting to do this with all files. My project files (and only my project files) are all .ts/.tsx. The options below in settings.json allow fix on save without it including every file in my repo: -
{
"editor.codeActionsOnSave": {
"source.fixAll.eslint": true
},
"eslint.probe": [
"typescript",
"typescriptreact"
],
}
If eslint.probe is not specified, it defaults to: -
["javascript", "javascriptreact", "typescript", "typescriptreact", "html", "vue"]
More about the VSCode ESLint extension settings can be found here.
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 .
An ESLint parser which leverages TypeScript ESTree to allow for ESLint to lint TypeScript source code.
If you intend on running ESLint from directories other than the project root, you should consider using tsconfigRootDir . Accepted values: // path project: './tsconfig.
To solve the error "Parsing Error: Cannot read file 'tsconfig. json'", update your . eslintrc. js file to set the tsconfigRootDir option to __dirname to force eslint to resolve your project configuration relative to the folder where .
Why this happens?
I'm not entirely sure, but it seems like @typescript-eslint/parser
tries to compare files covered in the eslint configuration (for example by extension) with files included in tsconfig.json
. Since the .js
files are covered by @typescript-eslint/parser and depending on your eslint configuration, the file is probably included in the eslint run. But because the file isn't included in tsconfig, you get this error.
How to fix that?
Depending on your case, you can select one of them:
.eslintignore
. This is what @U4EA did.tsconfig.json
: "include": [
".eslintrc.js",
// another includes
]
tsconfig.eslint.json
:{
"include": [
".eslintrc.js"
]
}
and use this file inside .eslintrc.js
for eslint only:
parserOptions: {
project: [
'./tsconfig.eslint.json',
'./packages/*/tsconfig.json',
],
},
You can also ignore .eslintrc.js in .eslintrc.js itself, saving you an additional file:
"ignorePatterns": [
".eslintrc.js"
],
can be helpful for VS Code users, uninstalling or disabling ESLint extension may solve this issue, it worked for me :)
Extension
I had a similar issue and I disabled the eslint extension on vs code and that was it for me. I'm assuming there was some kind of conflict between the global eslint and the one for my project.
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