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

@nx/dependency-checks incorrectly caches dependencies from first seen package.json for the entire run #20727

Closed
3 of 4 tasks
ComradeCow opened this issue Dec 12, 2023 · 2 comments · Fixed by #21404
Closed
3 of 4 tasks
Assignees
Labels
outdated scope: linter Issues related to Eslint support in Nx type: bug

Comments

@ComradeCow
Copy link

Current Behavior

We use lint-staged to enforce lint rules with a pre-commit hook. To speed that up, we're invoking eslint directly on the files that are changed (instead of invoking the lint target on affected projects).

If we have a commit with multiple package.json files, the lint rule assumes ALL packages use the dependencies of the first package. This means when it scans the second, third package.json file, it believes there are dependencies missing from those projects, even if the package.json files are correct.

The auto-fixer will end up adding duplicated dependencies to subsequent the package.json files (adding dependencies when it was already specified in the package.json)

We currently work around this issue by committing the package.json files one at a time.

Expected Behavior

The rule should work across multiple package.json files in a single eslint run.

The rule should emit the same errors regardless of the order the files are specified in.

The auto-fixer should not add

GitHub Repo

https://github.com/ComradeCow/nx-deps-lint-error

Steps to Reproduce

  1. Clone the sample repo - run npm install

  2. Run npx eslint packages/project1/package.json packages/project2/package.json
    The lint rule fails complaining pad-right is missing from project2

  3. Run npx eslint packages/project1/package.json
    No errors

  4. Run npx eslint packages/project2/package.json
    No errors

  5. Run npx eslint packages/project2/package.json packages/project1/package.json
    The lint rule fails, but pad-left is missing from project1

  6. Run npx eslint packages/project2/package.json packages/project1/package.json --fix
    pad-left will be added to project1's package.json a second time.

Nx Report

❯ nx report

 >  NX   Report complete - copy this into the issue template

   Node   : 20.6.1
   OS     : linux-x64
   npm    : 10.2.4
   
   nx (global)        : 17.1.1
   nx                 : 17.2.1
   @nx/js             : 17.2.1
   @nx/workspace      : 17.2.1
   @nx/devkit         : 17.2.1
   @nx/eslint-plugin  : 17.2.1
   @nrwl/tao          : 17.2.1
   typescript         : 5.3.3

Failure Logs

No response

Package Manager Version

10.1.0

Operating System

  • macOS
  • Linux
  • Windows
  • Other (Please specify)

Additional Information

No response

@AgentEnder AgentEnder added the scope: linter Issues related to Eslint support in Nx label Dec 21, 2023
@meeroslav meeroslav self-assigned this Jan 8, 2024
@meeroslav
Copy link
Contributor

Interesting find. Thank you for reporting this.

Copy link

github-actions bot commented Mar 4, 2024

This issue has been closed for more than 30 days. If this issue is still occuring, please open a new issue with more recent context.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 4, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
outdated scope: linter Issues related to Eslint support in Nx type: bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants