Skip to content

Feature Request: Skip plugin inference when target is explicitly defined in project.json #34030

@omer-za

Description

@omer-za

Current Behavior

When running a specific target (e.g., nx build my-app), Nx builds the entire project graph including running all plugin inference logic, even when the target is explicitly defined in the project's project.json.

This causes significant performance issues in large monorepos. In our case, the Jest plugin inference causes timeouts during Docker builds when we only need to run a build target that is already explicitly configured.

Expected Behavior

The logic should be:

  1. Check if the target exists explicitly in project.json
  2. If yes → execute it directly without full plugin inference
  3. If no → use only the relevant plugin to infer the target for that specific project

Workaround

We currently have to remove the plugins section from nx.json during Docker builds to avoid timeouts:

RUN node -e "const fs = require('fs'); const nx = JSON.parse(fs.readFileSync('nx.json')); delete nx.plugins; fs.writeFileSync('nx.json', JSON.stringify(nx, null, 2));"
RUN yarn build my-app

This feels like a hack and shouldn't be necessary.

Why This Matters

  • CI/CD Performance: Every build command rebuilds the entire graph, even for targets that don't need inference
  • Docker Builds: Plugin inference (especially Jest) can timeout in resource-constrained environments
  • Developer Experience: Running explicit targets should be fast and predictable

Proposal

Consider implementing lazy/on-demand plugin inference:

  • Only run plugin inference when actually needed (target not found in project.json)
  • Cache inference results more aggressively
  • Allow a flag like --skip-inference for commands targeting explicit targets

Environment

  • Nx version: 22.2.1
  • Package manager: yarn
  • Problematic plugin: @nx/jest/plugin (but applies to all inference plugins)

Would love to hear the team's thoughts on this optimization!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions