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

What code were you trying to parse?

any kind of sub module that is currently not used by any other module

What did you expect to happen?

What actually happened?

When using eslint on a sub module that is currently not used by any other module, the following type of error message is shown:

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

If I import the file in another module the error disappears.

This error message is relatively new and previous version of the @typescript-eslint/parser did not complain.

Versions

package version
@typescript-eslint/parser 2.2.0
TypeScript 3.6.3
ESLint 6.3.0
node 12.10.0
npm 6.11.2

About this issue

  • Original URL
  • State: closed
  • Created 7 years ago
  • Reactions: 15
  • Comments: 18 (11 by maintainers)

Most upvoted comments

Resarting VSCode solved this for me 🤔

@r-bman - #864, we’re working on it and should have a fix out soon.


@tsujp - the typescript compiler apis we utilise do not work this way; you have to pass it the path to a tsconfig.

We can’t really create a temporary tsconfig file in your project during lint, because we don’t know the structure of your folders (it’s also not a great practice to create temporary files in the project folder).

Additionally, whilst globs are reasonably fast, for some larger/deeply nested projects, providing such wide-reaching globs can cause perf issues. There’s also the problem of needing to make sure to exclude things like node_modules, and other things (like the coverage report folder created by test tools, build folders, config folders, template files, etc). If you select more files than necessary then you could severely impact perf by parsing / typechecking more files than necessary…

@doberkofler - looking at your zip repro, it’s all working as intended.

Your tsconfig has the following includes:

  "include": [
    "src/core"
  ],

Which means that src/util/util.ts is not included within the project. As such, we cannot parse it.

You have to ensure all files are included within the tsconfig.

   "include": [
+    "src/util",
     "src/core"
   ],

I made this change, ran yarn test, and everything worked as intended.

If you have many tsconfigs, you can provide as many or as few of them to the parser as you want, can see more information on this in the parser readme.

Alternately, you should create a separate tsconfig.eslint.json file, and just include every single file within that config (can see more information on this in the parser readme).

https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/parser/README.md#configuration

You need to update the include array in your tsconfig to include all fles you want to lint. That’s not exactly clear from any documentation

There’s a whole section on it in the readme… https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/parser/README.md#configuration

… you must only lint files that are included in the projects as defined by the provided tsconfig.json files. If your existing configuration does not include all of the files you would like to lint, you can create a separate tsconfig.eslint.json as follows:

Additionally, the error message that the parser gives you pretty explicitly states it as well:

The file must be included in at least one of the projects provided

Please let me know if any of the documentation is not clear enough.


if you’re using VScode you may need to reload it for the IDE to recognise the changes, CLI should be fine though.

We’re working to fix this #864

@JeffGuKang - a solution to what exactly? This particular “issue” isn’t going away in the next release.

This is how the parser works now. Either you configure it to include all your files, or you get parsing errors.

Failing to do so, and turning on createDefaultProgram as a bandaid will cause performance problems for your lint runs.

There is one issue which will be fixed soon (IDE errors when creating a new file), but that is unrelated to this thread.

@bradzacher Thank you very much for your extensive feedback and all the work you are doing on this project!

More information on why is located in the 2.0.0 release notes: https://github.com/typescript-eslint/typescript-eslint/releases/tag/v2.0.0

TL;DR is because if you don’t include the linted files within the tsconfigs you provide us, then it will cause a serious performance impact, which is O(n^m) where n is the number of files not included in the config, and m is the average depth of the dependency tree of those files. I.e. for some projects we’ve seen as much as a 10x slow down. The change introduced in 2.0 hard fails when we encounter a file outside of the tsconfigs, so it’s impossible for users to trigger this perf regression.


If you’ve got many tsconfig files, you can either:

  • provide them individually as an array of strings (eg project: ["./tsconfig.json", "./package1/tsconfig.json", ...].
  • provide them as a single (or multiple) globs (eg project: "./**/tsconfig.json")
  • mix and match the two (eg project: ["./tsconfig.json", "./**/tsconfig.json", ...])

My recommendation is to just do a new tsconfig.eslint.json in your project root which looks something like:

{
  "compilerOptions": { "strict": true },
  "include": [
    "**/src/**/*.ts",
    "**/test/**/*.ts",
    // etc
  ]
}

I’m going to close this for housekeeping purposes, because it looks like there’s no bug here. But we can keep discussing here!