typescript-eslint: v2.6.0: `Parsing error: "parserOptions.project" has been set for @typescript-eslint/parser.`
What code were you trying to parse?
A new, empty file.
What did you expect to happen?
No eslint error should occur in the VS Code IDE for the new file.
What actually happened?
When creating a new file in my src dir (which is in tsconfig.json) in any of my TypeScript projects, in VS Code, the following error immediately appears on the file (via the VS Code ESLint extension):
Parsing error: "parserOptions.project" has been set for @typescript-eslint/parser.
The file does not match your project config: src/test.ts.
The file must be included in at least one of the projects provided.
Versions
| package | version |
|---|---|
@typescript-eslint/parser |
2.6.0 |
TypeScript |
3.6.3 |
ESLint |
6.6.0 |
node |
12.12.0 |
npm |
6.12.1 |
Also, MacOS 10.14.6 and VS Code 1.39.2.
I know this issue has been mentioned several times in this repo, but it seems like they’re all closed. The issue was supposedly resolved in 2.6.0 of the parser, but it’s not fixed for me.
The new file I am creating are definitely in a directory that is included in tsconfig.json. The error disappears when I use Reload Window in VS Code, but I’d rather not want to do that for every new file I create, primarily because I have several scripts that run when a VS Code workspace is opened, and so I’d have to wait a few minutes after reloading the window.
.eslintrc.js:
{
"parser": "@typescript-eslint/parser",
"parserOptions": {
"project": "tsconfig.json"
},
"plugins": ["@typescript-eslint"],
"extends": ["plugin:@typescript-eslint/recommended"]
}
tsconfig.json:
{
"compilerOptions": {
"esModuleInterop": true,
"module": "CommonJS",
"outDir": "./dist/",
"resolveJsonModule": true,
"rootDir": "./src/",
"strict": true,
"target": "ES2020"
},
"include": ["./src/"],
"exclude": [
"**/build/**",
"**/coverage/**",
"**/dist/**",
"**/node_modules/**"
]
}
About this issue
- Original URL
- State: closed
- Created 7 years ago
- Reactions: 14
- Comments: 21 (9 by maintainers)
woo hoo, awesome @garyking - you’ve found the repro! Thanks
Typescript doesn’t like to be consistent, apparently 😞 If you provide
./src/, then it will ask us to watch the path<absolute_path>/src/. If you provide./src, then it will ask us to watch the path<absolute_path>/src.The code right now assumes the latter is how the watch path will always look. So when you create a the file:
./src/foo/bar/baz.ts, this is essentially what happens:<absolute_path>/src/foo/bar<absolute_path>/src/foo<absolute_path>/src<absolute_path>/src/, but string===match means it doesn’t match, ofc.Now that I know the problem it’s easy to normalise the paths and fix this.
The same problem happened
@diegohaz - your problem is logged in https://github.com/typescript-eslint/typescript-eslint/issues/1110 Workaround is to add an
includeto your tsconfig.@bradzacher I managed to narrow down the issue as far as I could. First, here are my files:
tsconfig.json:.eslintrc.js:I’m using the VS Code ESLint extension.
In VS Code, I create a file, like
src/a.ts. I get the error message. If IReload Window, then the error message is gone. Just like the issue has been described, so far.The key is
"include": ["./src/"]intsconfig.json. If you change it to"include": ["./src"](so, the final slash is removed), then the error will not appear.