Dependency-Checks ESLint Rule Fails for TypeScript Composite Projects in Nx 20.2.2
ashkanhosseini opened this issue · 1 comments
Current Behavior
When using the @nx/dependency-checks ESLint rule with TypeScript composite mode and references (without paths), the lint command incorrectly flags dependencies as unused.
Example error message:
/nx-next-release/packages/types-b/package.json
5:5 error The "@myorg/types-a" package is not used by "types-b" project @nx/dependency-checks
✖ 1 problem (1 error, 0 warnings)
1 error and 0 warnings potentially fixable with the `--fix` option.
Warning: command "eslint ." exited with non-zero status code
A workaround is to first build the packages and then run nx reset, followed by the lint command. However, this is not expected behavior, and the dependency graph appears to be correct at all stages.
Expected Behavior
The @nx/dependency-checks rule should correctly detect dependencies for TypeScript projects using composite mode and references, without requiring additional build or nx reset steps.
GitHub Repo
https://github.com/ashkanhosseini/nx-next-release/pull/3/files
Steps to Reproduce
-
Create a new Nx workspace using nx version 20.2.2.
-
Enable TypeScript composite mode with references.
-
Generate two publishable libraries:
types-a
npx nx g @nx/js:library packages/types-a --bundler=rollup --publishable --importPath=@myorg/types-a --verbose
types-b:
npx nx g @nx/js:library packages/types-b --bundler=rollup --publishable --importPath=@myorg/types-b --verbose
-
In types-a, create and export an arbitrary type.
-
In types-b, create another arbitrary type that extends the type from types-a.
-
Add the dependency in types-b/package.json:
"@myorg/types-a": "workspace:*"
-
Run
npx nx sync
-
Run the lint command:
npx nx lint types-b
Observed result:
The dependency-checks rule incorrectly reports that @myorg/types-a is not used by types-b.
Workaround
- build both packages:
npx nx build types-b
- reset the nx project graph:
npx nx reset
- run the lint again:
npx nx lint types-b
This sequence resolves the error temporarily, but it should not be necessary and this is going to make the CI runs inefficient anyways
you can use dependency-check
branch from this repository to have everything ready for testing.
Nx Report
NX Report complete - copy this into the issue template
Node : 20.18.1
OS : darwin-arm64
Native Target : aarch64-macos
yarn : 4.5.3
nx : 20.2.2
@nx/js : 20.2.2
@nx/jest : 20.2.2
@nx/eslint : 20.2.2
@nx/workspace : 20.2.2
@nx/devkit : 20.2.2
@nx/eslint-plugin : 20.2.2
@nx/module-federation : 20.2.2
@nx/react : 20.2.2
@nx/rollup : 20.2.2
@nx/web : 20.2.2
typescript : 5.6.3
---------------------------------------
Registered Plugins:
@nx/js/typescript
@nx/eslint/plugin
@nx/rollup/plugin
@nx/jest/plugin
Failure Logs
/nx-next-release/packages/types-b/package.json
5:5 error The "@myorg/types-a" package is not used by "types-b" project @nx/dependency-checks
✖ 1 problem (1 error, 0 warnings)
1 error and 0 warnings potentially fixable with the `--fix` option.
Warning: command "eslint ." exited with non-zero status code
—————————————————————————————————————————————————————————————————————————————————————————————————————
NX Ran target lint for project types-b (1s)
✖ 1/1 failed
✔ 0/1 succeeded [0 read from cache]
Package Manager Version
No response
Operating System
- macOS
- Linux
- Windows
- Other (Please specify)
Additional Information
No response