Skip to content

@nx/dependency-checks produces false positives in npm workspace children that have their own nx.json #35818

@piotretm

Description

@piotretm

Current Behavior

When using npm workspaces with multiple Nx workspace roots (each child workspace has its own nx.json), the @nx/dependency-checks ESLint rule reports all dependencies as unused. Every dependency in every library's
package.json gets flagged with "<package>" is not used.

Expected Behavior

@nx/dependency-checks should be able to resolve npm dependencies against the lockfile even when the Nx workspace root differs from the npm workspace root (i.e., the lockfile lives in a parent directory).

GitHub Repo

No response

Steps to Reproduce

  1. Create a monorepo with npm workspaces
  2. Add nx.json to a child workspace (e.g., frontend/lit/nx.json)
  3. Enable @nx/dependency-checks in that child workspace's ESLint config
  4. Run ESLint from the child workspace: cd frontend/lit && npx eslint libs/my-lib/package.json
  5. All dependencies are reported as unused
 ├── package.json                   ← workspaces: ["frontend/lit", "frontend/app"]
 ├── package-lock.json              ← single lockfile for all workspaces
 ├── nx.json                        ← root Nx workspace (optional)
 │
 └── frontend/lit/                  ← npm workspace child
     ├── nx.json                    ← nested Nx workspace root
     ├── package.json
     ├── .eslintrc.json             ← enables @nx/dependency-checks
     └── libs/
         └── my-lib/
             ├── package.json       ← declares dependencies (lit, rxjs, etc.)
             └── src/
                 └── index.ts       ← imports lit, rxjs, etc.```

### Nx Report

```shell
NX   Report complete - copy this into the issue template

Node           : 22.22.2
OS             : linux-x64
Native Target  : x86_64-linux
npm            : 10.9.7

nx                     : 21.6.10
@nx/js                 : 21.6.10
@nx/jest               : 21.6.10
@nx/eslint             : 21.6.10
@nx/workspace          : 21.6.10
@nx/angular            : 21.6.10
@nx/cypress            : 21.6.10
@nx/devkit             : 21.6.10
@nx/eslint-plugin      : 21.6.10
@nx/module-federation  : 21.6.10
@nx/playwright         : 21.6.10
@nx/plugin             : 21.6.10
@nx/storybook          : 21.6.10
@nx/vite               : 21.6.10
@nx/web                : 21.6.10
@nx/webpack            : 21.6.10
typescript             : 5.9.3
---------------------------------------
Cache Usage: 0.00 B / 100.69 GB

Failure Logs

Package Manager Version

npm --version 10.9.7

Operating System

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

Additional Information

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No fields configured for Bug.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions