Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Parsing error: "parserOptions.project" has been set for @typescript-eslint/parser. #5765

Closed
4 tasks done
jez9999 opened this issue Oct 7, 2022 · 8 comments
Closed
4 tasks done
Labels
bug Something isn't working external This issue is with another package, not typescript-eslint itself

Comments

@jez9999
Copy link

jez9999 commented Oct 7, 2022

Before You File a Bug Report Please Confirm You Have Done The Following...

  • I have tried restarting my IDE and the issue persists.
  • I have updated to the latest version of the packages.
  • I have searched for related issues and found none that matched my issue.
  • I have read the FAQ and my problem is not listed.

Issue Description

I recently added a couple of ESLint rules that required me to add this to my .eslintrc.cjs config:

	"parserOptions": {
		"ecmaVersion": "latest",
		"project": "./tsconfig.json",
		"parser": "@typescript-eslint/parser"
	},

This is causing the following error in VS Code in some of my TS and JS files:

Parsing error: "parserOptions.project" has been set for @typescript-eslint/parser.
The file does not match your project config: src\router.js.
The file must be included in at least one of the projects provided.

The weird thing is I will get this error in a TS file in a dir, but not in another TS file in the same dir. If I rename the file with the error (something like file.ts -> file2.ts), the error will disappear, and it appears when I rename it back, so I assume it's some weird caching issue.

In my example repo, I'm getting the error for src/router.js but not for src/main.js.

Reproduction Repository Link

https://gitlab.com/jez9999/eslint-bug

Repro Steps

  1. clone the repo
  2. npm install
  3. npm run lint

Versions

package version
TypeScript 4.8.4
ESLint 8.23.1
node 16.17.0
@jez9999 jez9999 added bug Something isn't working triage Waiting for maintainers to take a look labels Oct 7, 2022
@JoshuaKGoldberg
Copy link
Member

Interesting. #5762 should improve the error message a bit. Two things fix this locally for me:

My recommendation here would be to do either of those two things, or if you can't, set up a tsconfig.eslint.json as described in https://typescript-eslint.io/docs/linting/typed-linting/monorepos.

As to why those specific files do or don't get the parsing error... great question. Marking as this needing an investigation.

@JoshuaKGoldberg JoshuaKGoldberg added question Questions! (i.e. not a bug / enhancment / documentation) and removed bug Something isn't working labels Oct 7, 2022
@bradzacher
Copy link
Member

bradzacher commented Oct 10, 2022

Something weird is happening with the project references yeah.
How come you have both a tsconfig.json AND a tsconfig.app.json **that are exactly the same?

Similarly your tsconfig.vitest.json has no includes - which means it includes every single file in your project.

For some reason the combination of the duplicated tsconfig and the unrestricted includes in project references causes TS to exclude src/router.js from the program.

What makes it weirder is that TS gives us inconsistent information:

  • program.getRootFileNames() returns
    Set(3) {
      'env.d.ts',
      'src/main.js',
      'src/router.js'
    }
    
  • program.getSourceFiles() returns
    Set(34) {
      // ... snip node modules ...
      'env.d.ts',
      'src/main.js'
    }
    

So TS knows that src/router.js is a root file, but it doesn't create a source file for it.
I don't know why exactly. I was under the impression that TS should completely ignore the project references for our call. Probably worth following up with the TS folks? We'd need to create a repro without our library code - i.e. write small script which calls the TS APIs to reproduce this weird behaviour.

Regardless - cleaning up your project references so there's less duplication in the includes would be best.

I would suggest creating a single tsconfig for your entire project.

@bradzacher
Copy link
Member

I'm going to close this for now because there are workarounds provided.
We'll investigate following up with TS separately.

@bradzacher bradzacher added bug Something isn't working external This issue is with another package, not typescript-eslint itself and removed question Questions! (i.e. not a bug / enhancment / documentation) triage Waiting for maintainers to take a look labels Oct 10, 2022
@jez9999
Copy link
Author

jez9999 commented Oct 11, 2022

The trouble is, the default vue project created with npm init vue@3 wants to do this whole "multiple .tsconfig" thing, where different .tsconfig files have different values for "extends". I'm not sure exactly what that's doing so I'm not sure how to translate it all into one .tsconfig.

@bradzacher
Copy link
Member

@jez9999 check the guide I linked. It should help you setup a tsconfig.eslint.json to lint with.

@jez9999
Copy link
Author

jez9999 commented Oct 11, 2022

@bradzacher Vue 3's default setup has a tsconfig.json that references 3 other files, which themselves variously extend @vue/tsconfig/tsconfig.web.json and @vue/tsconfig/tsconfig.node.json. These different configs have different includes so they apply different settings to different sets of files. How can this be recreated with a single tsconfig.json or even a tsconfig.eslint.json?

@jez9999
Copy link
Author

jez9999 commented Oct 13, 2022

Interesting. #5762 should improve the error message a bit. Two things fix this locally for me:

My recommendation here would be to do either of those two things, or if you can't, set up a tsconfig.eslint.json as described in https://typescript-eslint.io/docs/linting/typed-linting/monorepos.

As to why those specific files do or don't get the parsing error... great question. Marking as this needing an investigation.

If you ask me, @JoshuaKGoldberg, supporting project references should be a very high priority for this project. They seem to have been around now for 4 years and are presumably widely used. It's somewhat ridiculous they're not supported. Also, I tried adding that experimental flag in .eslintrc.cjs, and it didn't fix the errors here at all:

	"parserOptions": {
		"ecmaVersion": "latest",
		"project": "./tsconfig.json",
		"parser": "@typescript-eslint/parser",
		"EXPERIMENTAL_useSourceOfProjectReferenceRedirect": true
	},

@bradzacher
Copy link
Member

bradzacher commented Oct 13, 2022

It's somewhat ridiculous they're not supported

That sort of statement is a really harmful, inflammatory statement. It is based on a lack of understanding of the volunteer maintainers' circumstances as well as the very large scope of the problem.

I would thank you to not use such a tone, especially when you're asking people to volunteer their free time to help you out.

If you ask me supporting project references should be a very high priority for this project

Project references aren't something you can simply support because we don't support them - TS APIs support them.
We need involvement from the TS team to properly support them, but we as volunteer maintainers haven't have the bandwidth to get involved in such a collaboration because it will take a lot of time to properly spec it, build it and test it.

Right now the APIs TS provides to work with project references are not good for us - there are a number of cases for which they break the type-aware linting; which is why the flag is EXPERIMENTAL.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Nov 13, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working external This issue is with another package, not typescript-eslint itself
Projects
None yet
Development

No branches or pull requests

3 participants