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 fails to detect dependencies after upgrade to nx 18 #22247

Closed
1 of 4 tasks
Helveg opened this issue Mar 9, 2024 · 28 comments
Closed
1 of 4 tasks
Assignees

Comments

@Helveg
Copy link

Helveg commented Mar 9, 2024

Current Behavior

I upgraded my workspace to nx 18. Linting passed before the upgrade, but after the upgrade @nx/dependency-checks started reporting all my dependencies as obsolete:

C:\Users\pwd06\git\gilbert\packages\ab-resources\package.json
   7:5  error  The "@angular/common" package is not used by "ab-resources" project  @nx/dependency-checks
   8:5  error  The "@angular/core" package is not used by "ab-resources" project    @nx/dependency-checks
   9:5  error  The "chart.js" package is not used by "ab-resources" project         @nx/dependency-checks
  10:5  error  The "date-fns" package is not used by "ab-resources" project         @nx/dependency-checks
  11:5  error  The "deepmerge-ts" package is not used by "ab-resources" project     @nx/dependency-checks

Worthy to note: The dependencies on other libraries in the workspace is still detected, and visible in the project graph with nx graph.

Expected Behavior

These dependencies were detected before, and are imported in the source code, and analyzeSourceFiles is enabled for @nx/js, so I expect them to be detected like in nx@17

GitHub Repo

No response

Steps to Reproduce

Not sure, it might be due to the history of my Nx workspace, willing to follow diagnostic instructions to figure out a reproducer.

Nx Report

Node   : 20.9.0
OS     : win32-x64
npm    : 9.1.2

nx (global)        : 18.0.8
nx                 : 18.0.8
@nx/js             : 18.0.8
@nx/jest           : 18.0.8
@nx/linter         : 18.0.8
@nx/eslint         : 18.0.8
@nx/workspace      : 18.0.8
@nx/angular        : 18.0.8
@nx/cypress        : 18.0.8
@nx/devkit         : 18.0.8
@nx/eslint-plugin  : 18.0.8
@nx/nest           : 18.0.8
@nx/node           : 18.0.8
@nrwl/tao          : 18.0.8
@nx/web            : 18.0.8
@nx/webpack        : 18.0.8
typescript         : 5.3.3
---------------------------------------
Community plugins:
@auth0/auth0-angular : 2.2.3
@ngrx/component      : 17.1.1

Failure Logs

No response

Package Manager Version

No response

Operating System

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

Additional Information

Using "checkObsoleteDependencies": false I can disable the removal of my existing dependencies for now.

@FrozenPandaz FrozenPandaz added the scope: linter Issues related to Eslint support in Nx label Mar 15, 2024
@L-NiNo
Copy link

L-NiNo commented Mar 21, 2024

Helveg i had this issue during upgrading and discovered I that the package-lock is required to pull 3rd party imports correctly. I opened a issue to add it to the documentation #22442.

It might not be applicable to your use case, but worth mentioning.

@FrozenPandaz
Copy link
Collaborator

So the lint rule is definitely able to find these dependencies here in the Nx repo. We'll need more information in order to help you resolve your issue.

What version did you migrate from?
Does nx reset fix the issue?
Is it possible to provide a minimal reproduction to make reproducing the issue easier?

@Helveg
Copy link
Author

Helveg commented Apr 2, 2024

So I think I had the same issue as @L-NiNo. Since removing package-lock.json is a pretty common operation during a major version migration of a peer dependency (e.g. the main frameworks used in the project), I think @nx/dependency-checks should warn and noop, or error out when there's no package-lock.json to derive dependencies from.

With package-lock.json present in the root directory @nx/dependency-checks seems to operate normally again.

Copy link

This issue has been automatically marked as stale because it hasn't had any recent activity. It will be closed in 14 days if no further activity occurs.
If we missed this issue please reply to keep it active.
Thanks for being a part of the Nx community! 🙏

@github-actions github-actions bot added the stale label Apr 17, 2024
@binaryartifex
Copy link

binaryartifex commented Apr 23, 2024

can confirm. ive wasted an entire afternoon on this damn thing. this linting plugin has just suddenly decided all the deps in the plugins package.json arn't being used. they certainly are. ive redownloaded deps, reset nx a million which ways.

  1. create a plugin using the nx generator using the swc compiler at plugins/foobar
  2. in the package.json there should be an swc helpers dependency
  3. run linting. watch linting fail.
  4. run build. watch build output a warning also saying Your library compilation option specifies that the compiler external helper (@swc/helpers) is needed but it is not installed. it also proceeds to tell me all the packages that are being imported into it from the workspace are outside the configured rootDir of plugin/[myplugin]. ive tried setting the rootDir all over the place and its just ignored.

@Helveg
Copy link
Author

Helveg commented Apr 23, 2024

@binaryartifex what about your package-lock.json? Also, even stupider, have you tried fully restarting your computer? I basically just disabled the plugin, came back to it a few days later, and it suddenly worked again.

I used these options to disable the failing linting rules:

      "checkMissingDependencies": true, // toggle to disable
      "checkObsoleteDependencies": true, // toggle to disable
      "checkVersionMismatches": true // toggle to disable

set them to false to disable

@binaryartifex
Copy link

that takes care of the linting but honestly kinda defeats the purpose of a build package linter in the first place. the build step however has suddenly decided not to work at all. workspace plugins never use to have their own package.json, which was great for simple executors, etc that you wanted within the scope of your own integrated monorepo. reference my concern above with the build executor not finding swc helpers at all, ffs, they are installed, they are in the package.json of the plugin, its never been an issue before...wtf? utilities in the libs external to the plugin all of a sudden cannot be imported. there's now what must be a static rootDir set somewhere that refuses to be overridden so i can't tell this bloody thing it can in fact, look outside the plugin for its imports....what was meant to be literally a swap out for a business logo has got me grinding into the night to fix yet another random nx issue....sigh

@github-actions github-actions bot removed the stale label Apr 24, 2024
@L-NiNo
Copy link

L-NiNo commented Apr 25, 2024

Helveg i had this issue during upgrading and discovered I that the package-lock is required to pull 3rd party imports correctly. I opened a issue to add it to the documentation #22442.

It might not be applicable to your use case, but worth mentioning.

Also worth noting, package-lock cannot be gitignored

@DenizUgur
Copy link

I'm using pnpm and cannot actually pinpoint when this rule stopped working but even though my library is buildable the rule does not detect dependencies used in my project. How does this rule even work in the first place? Maybe I'm missing something that broke this rule.

Copy link

github-actions bot commented May 9, 2024

This issue has been automatically marked as stale because no reproduction was provided within 7 days.
Please help us help you. Providing a repository exhibiting the issue helps us diagnose and fix the issue.
Any time that we spend reproducing this issue is time taken away from addressing this issue and other issues.
This issue will be closed in 21 days if a reproduction is not provided.
If a reproduction has been provided, please reply to keep it active.
Thanks for being a part of the Nx community! 🙏

@github-actions github-actions bot added the stale label May 9, 2024
@fahslaj fahslaj assigned JamesHenry and unassigned fahslaj May 14, 2024
@github-actions github-actions bot removed the stale label May 15, 2024
@marcolongol
Copy link
Contributor

Can confirm this is happening with me as well and it started after i added @nxlv/python to my monorepo and creating a new python project

C:\Users\lucas\OneDrive\Desktop\Sandbox\marcolongoldt\marcolongo.cloud\libs\common-ui\package.json
   5:5  warning  The "@angular/common" package is not used by "common-ui" project         @nx/dependency-checks
   6:5  warning  The "@angular/core" package is not used by "common-ui" project           @nx/dependency-checks
   7:5  warning  The "@angular/router" package is not used by "common-ui" project         @nx/dependency-checks
   8:5  warning  The "@marcolongo.cloud/core" package is not used by "common-ui" project  @nx/dependency-checks
  10:5  warning  The "@pdftron/webviewer" package is not used by "common-ui" project      @nx/dependency-checks

NX Report:

Node   : 20.13.1
OS     : win32-x64
npm    : 10.5.2

nx                 : 19.0.4
@nx/js             : 19.0.4
@nx/jest           : 19.0.4
@nx/linter         : 19.0.4
@nx/eslint         : 19.0.4
@nx/workspace      : 19.0.4
@nx/angular        : 19.0.4
@nx/cypress        : 19.0.4
@nx/devkit         : 18.3.4
@nx/eslint-plugin  : 19.0.4
@nx/storybook      : 19.0.4
@nrwl/tao          : 19.0.4
@nx/web            : 19.0.4
@nx/webpack        : 19.0.4
typescript         : 5.4.5
---------------------------------------
Registered Plugins:
@nxlv/python
@nx/cypress/plugin
@nx/eslint/plugin
---------------------------------------
Community plugins:
@fortawesome/angular-fontawesome : 0.14.1
@jscutlery/semver                : 5.2.2
@nx-tools/nx-container           : 6.0.0
@nxlv/python                     : 18.1.0
@storybook/angular               : 8.1.1
nx-stylelint                     : 17.1.4
---------------------------------------
The following packages should match the installed version of nx
- @nx/[email protected]
- @nrwl/[email protected]

To fix this, run `nx migrate [email protected]`

For now, i have changed the rule to warn untill it's fixed:

    {
      "files": ["*.json"],
      "parser": "jsonc-eslint-parser",
      "rules": {
        "@nx/dependency-checks": "warn"
      }
    }

Copy link

This issue has been automatically marked as stale because no reproduction was provided within 7 days.
Please help us help you. Providing a repository exhibiting the issue helps us diagnose and fix the issue.
Any time that we spend reproducing this issue is time taken away from addressing this issue and other issues.
This issue will be closed in 21 days if a reproduction is not provided.
If a reproduction has been provided, please reply to keep it active.
Thanks for being a part of the Nx community! 🙏

@github-actions github-actions bot added the stale label May 25, 2024
@tinesoft
Copy link
Contributor

I have the same issue here

I confirm it has something to do with package manager used (I'm using pnpm),
When removing the node_modules and pnpm-lock.yaml, then reinstalling the deps with pure npm,
the lint results are slightly better:

  • used external dependencies are detected properly
  • BUT
    • internal wildcard dependencies (example: "my-package": "*") are removed after linting with --fix ...

See my repo at https://github.com/tinesoft/nxrocks/

@github-actions github-actions bot removed the stale label May 28, 2024
@beeman
Copy link
Contributor

beeman commented May 29, 2024

I also have issues with the @nx/dependency-checks plugin. It tries to remove dependencies that I depend on.

Here is one of the repos where this happens but I have it in various.

image image

@JamesHenry
Copy link
Collaborator

JamesHenry commented May 30, 2024

@beeman are there steps required to reproduce this?

When I do a fresh clone of your repo, I get this lint feedback, which seems to be accurate:

7:5 error The version specifier does not contain the installed version of "@pubkey-program-library/anchor" package: 1.5.0 @nx/dependency-checks

image

@beeman
Copy link
Contributor

beeman commented May 30, 2024

@beeman are there steps required to reproduce this?

When I do a fresh clone of your repo, I get this lint feedback, which seems to be accurate:

Thanks for testing this @JamesHenry! Can you try switching to the beeman/identity-providers branch and see what that does?

@JamesHenry
Copy link
Collaborator

@beeman you are using pnpm lockfile v9 which is not supported by the Nx version you are using. We merged support for it already and it will be available in the upcoming Nx 19.2.

When I check out that branch and run pnpm install, my installed (supported) v8 version of pnpm rewrites the lock file automatically because it doesn't recognize it.

Linting passes in this scenario:

image

So in your case it is likely down to the unsupported lock file.

The latest prerelease for 19.2 is currently being released, so I will try that on your branch once it is ready without any modifications to your lock file to compare.

@JamesHenry
Copy link
Collaborator

@beeman Confirmed, yours is down to the unsupported lock file only. 19.2 prereleases, such as 19.2.0-beta.2, resolve the issue on that branch.

@JamesHenry
Copy link
Collaborator

Please can all others on this thread try updating to 19.2.0-beta.2 and seeing if it resolves their issues? We believe it should as it more accurately matches external nodes (npm packages) to projects

@beeman
Copy link
Contributor

beeman commented May 31, 2024

@beeman Confirmed, yours is down to the unsupported lock file only. 19.2 prereleases, such as 19.2.0-beta.2, resolve the issue on that branch.

Thanks a lot for checking this out and suggesting the solution! I'll test the new version and confirm back here!

@beeman
Copy link
Contributor

beeman commented Jun 4, 2024

@beeman Confirmed, yours is down to the unsupported lock file only. 19.2 prereleases, such as 19.2.0-beta.2, resolve the issue on that branch.

Just updated to the latest beta and this fixes this issue in my repo! Thanks! 🙏

Copy link

This issue has been automatically marked as stale because no reproduction was provided within 7 days.
Please help us help you. Providing a repository exhibiting the issue helps us diagnose and fix the issue.
Any time that we spend reproducing this issue is time taken away from addressing this issue and other issues.
This issue will be closed in 21 days if a reproduction is not provided.
If a reproduction has been provided, please reply to keep it active.
Thanks for being a part of the Nx community! 🙏

@github-actions github-actions bot added the stale label Jun 12, 2024
@MPFGlaser
Copy link

I still have issues with this, even on v19. Might have something to do with me using publishable libraries only in my project.

@github-actions github-actions bot removed the stale label Jun 28, 2024
@Markus-Ende
Copy link

Had the same issue when upgrading to 19.3.2, using npm. Was fixed by re-generating package-lock.

Copy link

github-actions bot commented Jul 7, 2024

This issue has been automatically marked as stale because no reproduction was provided within 7 days.
Please help us help you. Providing a repository exhibiting the issue helps us diagnose and fix the issue.
Any time that we spend reproducing this issue is time taken away from addressing this issue and other issues.
This issue will be closed in 21 days if a reproduction is not provided.
If a reproduction has been provided, please reply to keep it active.
Thanks for being a part of the Nx community! 🙏

@github-actions github-actions bot added the stale label Jul 7, 2024
@github-actions github-actions bot closed this as not planned Won't fix, can't repro, duplicate, stale Jul 28, 2024
@jkossis
Copy link

jkossis commented Aug 6, 2024

Ran into this just now, on 19.5.6. Anyone else seeing this?

@Hotell
Copy link
Contributor

Hotell commented Aug 12, 2024

@JamesHenry tried to enable this rule today and following getting weird errors:

image

I also noticed that projectFileMap is generated in weird way - the deps is completely missing

 {
      file: 'packages/react-components/react-text/library/src/components/presets/Body1Stronger/index.ts',
      hash: '2880256041137615974'
    },
    {
      file: 'packages/react-components/react-text/library/src/components/presets/Body1Stronger/useBody1StrongerStyles.styles.ts',
      hash: '17438350325437671483'
    },
    {
      file: 'packages/react-components/react-text/library/src/components/presets/Body2/Body2.tsx',
      hash: '16105280774354904702'
    },
    {
      file: 'packages/react-components/react-text/library/src/components/presets/Body2/index.ts',
      hash: '7846029568414333221'
    },

which will result in empty npmDependencies collection within the rule as this will never be executed
image

NOTE: we don't use source analyzer because legacy reasons

  "pluginsConfig": {
    "@nx/js": {
      "analyzeSourceFiles": false
    }
  },

quick repro:

{
  "root": true,
  "parser": "@typescript-eslint/parser",
  "plugins": ["@nx","@typescript-eslint"],
  "env": {
    "browser": true
  },
  "rules": {
    "import/no-extraneous-dependencies": "off",
    "react-compiler/react-compiler": "off"
  },
  "overrides": [
    {
      "files": ["*.json"],
      "parser": "jsonc-eslint-parser",
      "rules": {
        "@nx/dependency-checks": "error"
      }
    }
  ]
}

  • update scripts/tasks/src/eslint.ts#7 to const files = [path.join(process.cwd(), 'package.json'), path.join(process.cwd(), eslintConstants.directory)];
  • run yarn workspace @fluentui/react-text lint

Copy link

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 Sep 12, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests