Skip to content

Nested Project Files Excluded from Parent Project Inputs #34225

@AlonMiz

Description

@AlonMiz

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:

  1. Changes to nested project files don't invalidate the parent task's cache
  2. nx affected doesn't include the parent project when only nested project files change
  3. 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

  1. Clone the reproduction repository
  2. Run npm install
  3. Run nx run parent-lib:lint - lints all files including nested-lib/src/
  4. Run nx run parent-lib:lint again - correctly uses cache
  5. Modify packages/parent-lib/nested-lib/src/index.ts (add a comment or change code)
  6. Run nx run parent-lib:lint - BUG: incorrectly uses cache
  7. Run nx show project parent-lib --json and observe that nested-lib files are not in the inputs
  8. 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.0

Failure 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:

  1. Uses nested project structures (common in large codebases for logical grouping)
  2. Has parent-level tasks that process all files including nested ones
  3. Relies on Nx caching or nx affected for 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

  1. Add includeNestedProjects option to input globs
  2. Automatic detection: Analyze task options and include files that would be processed
  3. 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.

Metadata

Metadata

Assignees

Labels

Type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions