-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Closed
Description
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:
- Check if the target exists explicitly in
project.json - If yes → execute it directly without full plugin inference
- 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-appThis 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-inferencefor 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!
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels