-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Description
Current Behavior
When a parent project contains a nested project (a project.json inside another project's directory), Nx automatically excludes the nested project's files from the parent project's inputs calculation. However, tasks like lint that use glob patterns such as {projectRoot}/**/*.ts in their options (e.g., lintFilePatterns) still process those nested project files.
This creates a mismatch:
- Task execution: Processes files from both parent and nested projects
- Cache calculation: Only considers files from the parent project (excludes nested)
As a result:
- Changes to nested project files don't invalidate the parent task's cache
nx affecteddoesn't include the parent project when only nested project files change- CI pipelines incorrectly skip tasks, missing potential errors in nested project files
Expected Behavior
When a task's options (like lintFilePatterns) include files from nested projects via glob patterns, those files should be included in the cache input calculation. The cache should be invalidated when any file that the task actually processes is modified.
Alternatively, Nx should provide a way to explicitly include nested project files in inputs, such as:
{
"inputs": [
{ "glob": "{projectRoot}/**/*.ts", "includeNestedProjects": true }
]
}GitHub Repo
No response
Steps to Reproduce
- Clone the reproduction repository
- Run
npm install - Run
nx run parent-lib:lint- lints all files includingnested-lib/src/ - Run
nx run parent-lib:lintagain - correctly uses cache - Modify
packages/parent-lib/nested-lib/src/index.ts(add a comment or change code) - Run
nx run parent-lib:lint- BUG: incorrectly uses cache - Run
nx show project parent-lib --jsonand observe thatnested-libfiles are not in the inputs - Run
nx affected -t lint- BUG: parent-lib is not listed as affected
Expected at step 6: Cache should be invalidated, lint should run
Expected at step 8: parent-lib should be listed as affected
Nx Report
> nx report
Node : 20.20.0
OS : darwin-arm64
npm : 10.8.2
nx : 22.4.0
@nx/js : 22.4.0
@nx/eslint : 22.4.0
@nx/workspace : 22.4.0Failure Logs
No error logs - the issue is silent incorrect behavior. The task uses cache when it shouldn't.
Running with `NX_VERBOSE_LOGGING=true`:
nx run parent-lib:lint
> nx run parent-lib:lint [existing outputs match the cache, left as is]
The cache hit occurs even though a file that the lint task processes has been modified.Package Manager Version
npm 10.8.2
Operating System
- macOS
- Linux
- Windows
- Other (Please specify)
Additional Information
Why This Matters
This issue affects any monorepo that:
- Uses nested project structures (common in large codebases for logical grouping)
- Has parent-level tasks that process all files including nested ones
- Relies on Nx caching or
nx affectedfor CI optimization
The mismatch between "what the task does" and "what Nx thinks the task depends on" undermines the reliability of caching and affected detection.
Current Workarounds (All Suboptimal)
Workaround 1: Explicitly add nested project files to inputs
{
"targets": {
"lint": {
"inputs": [
"default",
"{projectRoot}/**/*.ts",
"{workspaceRoot}/packages/parent-lib/nested-lib/**/*.ts"
]
}
}
}Problem: Hardcodes paths, must be updated when nested projects change, violates DRY.
Workaround 2: Exclude nested files from task and create separate task
{
"targets": {
"lint": {
"dependsOn": ["nested-lib:lint"],
"options": {
"lintFilePatterns": [
"{projectRoot}/**/*.ts",
"!{projectRoot}/nested-lib/**/*"
]
}
}
}
}Problem: Requires restructuring tasks, complex configuration, may require splitting thresholds.
Workaround 3: Don't use nested projects
Problem: Major refactoring, loses logical grouping benefits.
Proposed Solutions
- Add
includeNestedProjectsoption to input globs - Automatic detection: Analyze task options and include files that would be processed
- Warning: At minimum, warn when task options reference files excluded from inputs
Root Cause
The glob pattern {projectRoot}/**/* has different semantics depending on context:
- In task options (e.g.,
lintFilePatterns): Literal filesystem glob, includes all files - In
inputs: Nx-aware glob, excludes files belonging to other projects
This inconsistency is not documented and leads to unexpected behavior.