Skip to content

Bug: multiple rootDirs in monorepo not honoured #7884

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

Closed
4 tasks done
squirmy opened this issue Nov 6, 2023 · 4 comments
Closed
4 tasks done

Bug: multiple rootDirs in monorepo not honoured #7884

squirmy opened this issue Nov 6, 2023 · 4 comments
Labels
awaiting response Issues waiting for a reply from the OP or another party bug Something isn't working triage Waiting for team members to take a look

Comments

@squirmy
Copy link

squirmy commented Nov 6, 2023

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 expected that linting should have no issues, however it gets:

> @eslint-root-dirs-issue/two@1.0.0 lint /Users/squirmy/code/eslint-root-dirs-issue/packages/two
> eslint .


/Users/squirmy/code/eslint-root-dirs-issue/packages/two/src/index.ts
    10:9  error  Unsafe assignment of an `any` value  ts/no-unsafe-assignment
    15:9  error  Unsafe assignment of an `any` value  ts/no-unsafe-assignment

✖ 2 problems (2 errors, 0 warnings)

 ELIFECYCLE  Command failed with exit code 1.

I suspect it has something to do with two not knowing to follow the multiple root dirs that are defined in one's tsconfig.json. VSCode is able to show the types when hovering over the variables, but linting shows errors in both vscode and when running from the command line.

Reproduction Repository Link

https://github.com/squirmy/eslint-root-dirs-issue

Repro Steps

  1. clone the repo
  2. pnpm install
  3. pnpm lint

Versions

package version
@typescript-eslint/eslint-plugin 6.9.1
@typescript-eslint/parser 6.9.1
TypeScript 5.2.2
ESLint 8.53.0
node 20.9.0
@squirmy squirmy added bug Something isn't working triage Waiting for team members to take a look labels Nov 6, 2023
@bradzacher
Copy link
Member

There's a lot of layers and indirection to this repro - tsconfigs extend tsconfigs, ESLint configs extend ESLint configs which extend utility functions from npm, linting is done by a separate tool.

Could you please slim the repro down a bit? Ideally the only npm deps should be TS, ESLint, and our parser+plugin.

@bradzacher bradzacher added the awaiting response Issues waiting for a reply from the OP or another party label Nov 6, 2023
@squirmy
Copy link
Author

squirmy commented Nov 6, 2023

Thanks @bradzacher - i've simplified the repository now.

  • Removed the config packages, and put the config directly into one and two packages.
  • Remove the dependency on the linting setup and put the minimal eslint config into the packages.

I'm not sure what you mean by "linting is done by a separate tool". It's only using eslint. There is Nx (monorepo tooling) invoking this on each package but that's it.

If you would like to avoid this you can:

  1. cd packages/two
  2. pnpm lint

It's worth noting that whilst this is using the flat config, I was previously using the .eslintrc.js file and had the same issues.

I've also tried using the EXPERIMENTAL_useProjectService option based on this issue:
#2094

But that doesn't seem to make a difference in this scenario.

@bradzacher
Copy link
Member

bradzacher commented Nov 6, 2023

I haven't had a chance to check things out locally yet but looking around at the setup - it makes sense that it's not working.

Even though your second package is part of the monorepo - it's imported as if it were an npm package and its source is included via a symlink that's managed by pnpm.

TypeScript doesn't respect the tsconfig of npm packages. If you want it to understand that the you will need to leverage project references like we do in our repo.

@squirmy
Copy link
Author

squirmy commented Nov 7, 2023

Ah, I see what you're saying. And you're right even though VSCode shows the name of the type, it doesn't know what that type actually is. I'll close the issue as you're right it's about how typescript is behaving and not the linting.

FYI, I just tried to use project references, and got the same errors. I believe it's because of this:

From Caveats for Project References

Because dependent projects make use of .d.ts files that are built from their dependencies, you’ll either have to check in certain build outputs or build a project after cloning it before you can navigate the project in an editor without seeing spurious errors.

If this requires a build step, then I think I might prefer to build the package and its types and expose it through the package.json module and types properties.

Something like:

  "module": "./dist/index.js",
  "types": "./dist/index.d.ts",

The downside is that things won't be as dynamic for a development experience. This can be worked around by having a build watch the files for changes. I was trying to avoid doing that, hoping there was a lighter weight solution.

Thanks for your help, and quick responses :)

@squirmy squirmy closed this as completed Nov 7, 2023
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Nov 15, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
awaiting response Issues waiting for a reply from the OP or another party bug Something isn't working triage Waiting for team members to take a look
Projects
None yet
Development

No branches or pull requests

2 participants