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

parserOptions.project doesnt handle project references well #856

Closed
milesj opened this issue Aug 14, 2019 · 15 comments · Fixed by #884
Closed

parserOptions.project doesnt handle project references well #856

milesj opened this issue Aug 14, 2019 · 15 comments · Fixed by #884
Labels
documentation Documentation ("docs") that needs adding/updating package: parser Issues related to @typescript-eslint/parser

Comments

@milesj
Copy link
Contributor

milesj commented Aug 14, 2019

What code were you trying to parse?

Not parsing code exactly, but I'm attempting to upgrade to v2, which hard fails if project doesn't include files correctly. This doesn't seem to handle project references correctly.

Given this root tsconfig.json:

{
  "files": [],
  "references": [
    {
      "path": "packages/config-danger"
    }
  ],
  "extends": "./tsconfig.options.json"
}

And this config-danger/tsconfig.json:

{
  "compilerOptions": {
    "declarationDir": "lib",
    "outDir": "lib",
    "rootDir": "src"
  },
  "exclude": [
    "lib",
    "tests"
  ],
  "extends": "../../tsconfig.options.json",
  "include": [
    "src/**/*",
    "types/**/*",
    "../../types/**/*"
  ],
  "references": []
}

What did you expect to happen?

Files within a project reference include worked correctly.

What actually happened?

The parser/plugin fails with a ton of the following errors:

/root/packages/config-danger/src/code.ts
  0:0  error  Parsing error: If "parserOptions.project" has been set for @typescript-eslint/parser, /root/packages/config-danger/src/code.ts must be included in at least one of the projects provided

Versions

package version
@typescript-eslint/parser 2.0.0
TypeScript 3.5.2
ESLint 6.1.0
node 12.8.0
npm 6.1.0.3
@milesj milesj added package: parser Issues related to @typescript-eslint/parser triage Waiting for maintainers to take a look labels Aug 14, 2019
@bradzacher
Copy link
Member

Hmm, I'm not sure what the typescript compiler actually does to handle project references. I haven't actually used them yet (I've been meaning to migrate this monorepo to them, but I keep forgetting).

Perhaps @uniqueiniquity has more of an idea than I do.
Is TS supposed to "include" all of the files in the referenced projects, or are they consumed via a different mechanism?

@milesj - could you please try using the array form of project to specify all of your tsconfigs?

{
  "parserOptions": {
    "project": [
      "tsconfig.json",
      "packages/config-danger/tsconfig.json"
    ]
  }
}

@MichalLytek
Copy link

I can confirm that the array of projects work but it's really making its hard to maintain:

    project: [
      path.resolve(__dirname, "./tsconfig.json"),
      path.resolve(__dirname, "./packages/core/tsconfig.json"),
      path.resolve(__dirname, "./packages/core/tests/tsconfig.json"),
      path.resolve(__dirname, "./packages/class-validator/tsconfig.json"),
      path.resolve(__dirname, "./packages/class-validator/tests/tsconfig.json"),
    ],

I suffer from this issue since v2.0 and its breaking change:

by default we will now throw when a file is not in the project provided

@uniqueiniquity
Copy link
Contributor

uniqueiniquity commented Aug 15, 2019

Hmm, I'm not sure what the typescript compiler actually does to handle project references. I haven't actually used them yet (I've been meaning to migrate this monorepo to them, but I keep forgetting).

Perhaps @uniqueiniquity has more of an idea than I do.
Is TS supposed to "include" all of the files in the referenced projects, or are they consumed via a different mechanism?

They are consumed by a different mechanism - in particular, the goal of project references is that when project a references project b, project a does not include the .ts files in project b.

@bradzacher bradzacher added documentation Documentation ("docs") that needs adding/updating and removed triage Waiting for maintainers to take a look labels Aug 15, 2019
@bradzacher
Copy link
Member

@19majkel94 - there is #806 which will make this easier by allowing you to supply a glob matcher for tsconfig files.


They are consumed by a different mechanism - in particular, the goal of project references is that when project a references project b, project a does not include the .ts files in project b.

Interesting. That's good to know, thanks.

We should probably document this clearly so people don't assume they only need to provide one of the tsconfigs in the project.

@justnewbee

This comment has been minimized.

@bradzacher

This comment has been minimized.

@lidianhao123

This comment has been minimized.

@milesj
Copy link
Contributor Author

milesj commented Aug 16, 2019

Can confirm using an array of tsconfig.json fixed the problem. I just did it programmatically with this.

const pkg = getPackage();
const project = [fromRoot('tsconfig.json')];

if (pkg.workspaces) {
  project.push(
    ...glob.sync(pkg.workspaces.map(ws => path.join(ws, 'tsconfig.json')), {
      absolute: true,
      onlyFiles: true,
    }),
  );
}

@justnewbee

This comment has been minimized.

@justnewbee

This comment has been minimized.

@bradzacher

This comment has been minimized.

@bradzacher
Copy link
Member

FYI #806 (glob selectors for parserOptions.project) has now been merged to master - so it'll be available on the canary tag on NPM imminently.

@milesj
Copy link
Contributor Author

milesj commented Aug 19, 2019

👏

@wintercounter
Copy link

I'm having the same issue. I have include field in my tsconfig.json as follows:

"include": [
    "C:\\Work\\Repos\\my-repo\\src\\**\\*"
  ],

Then I get the error:

0:0  error  Parsing error: If "parserOptions.project" has been set for @typescript-eslint/parser, C:\Work\Repos\my-repo\src\screens\Home\Sections\Top.tsx must be included in at least one of the projects provided.

I guess this is false and the pattern for some reason isn't matching (while in TS it does).

@bradzacher
Copy link
Member

Please follow the steps in #890.

Locking this issue to direct all further conversation to that issue

@typescript-eslint typescript-eslint locked as resolved and limited conversation to collaborators Aug 20, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
documentation Documentation ("docs") that needs adding/updating package: parser Issues related to @typescript-eslint/parser
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants