Skip to content

feat(core): suggest available targets and closest task id on run-one errors#35863

Open
AgentEnder wants to merge 3 commits into
masterfrom
show-available-targets
Open

feat(core): suggest available targets and closest task id on run-one errors#35863
AgentEnder wants to merge 3 commits into
masterfrom
show-available-targets

Conversation

@AgentEnder

Copy link
Copy Markdown
Member

Current Behavior

When nx run can't resolve the project or target, the error gives no guidance:

  • Unknown target on a real project surfaces deep inside the task graph builder as a bare Cannot find configuration for task <project>:<target> — no list of what is available, no spelling help.
  • Unknown project just prints Cannot find project '<name>' with no suggestion of what the user might have meant.
  • A typo in a target/configuration that happens to contain a : (a legal target name in Nx) gets parsed into separate target + configuration parts by splitTarget, so any naive similarity match against the bare target can never find the real colon-containing name.

Expected Behavior

run-one now validates the project and target up front and produces a friendly error before reaching the task-graph stage.

Unknown target:

 NX   Cannot find target "biuld" for project "my-app"

   Did you mean "build"?

   Available targets:
     - build
     - run
     - serve
  • The available-targets list is capped at 5 with a ...and N more line so output stays scannable on big projects.
  • The Did you mean suggestion uses Levenshtein distance with a length-relative threshold, so it stays silent for total nonsense.

Unknown project — including a colon target:

 NX   Cannot find project 'nxx'

   Did you mean one of these?
     - nx:zzcustom:variant

The attempted project:target[:configuration] is matched against every project:target task id in the graph, so project typos surface the real invocation (webpai:buildwebapi:build), and project typos against colon-named targets still resolve (nxx:zzcustom:variantnx:zzcustom:variant).

Colon-containing target/configuration names:
Because splitTarget parses the trailing segment off into a configuration, both error builders try the fully rejoined specifier first, then progressively shorter forms. So nx:zzcustom:variantt suggests zzcustom:variant, while genuine target + configuration typos (biuld:productionbuild) keep matching via the shorter-form fallback.

Implementation notes

  • New packages/nx/src/utils/string-similarity.ts with findClosestMatch / findClosestMatches (Levenshtein + length-relative threshold).
  • run-one.ts adds exported, unit-testable helpers getRunOneTargetError and getCannotFindProjectError, a shared findClosestSpecifier that tries longest-first, and formatAvailableTargets for the capped list.
  • 46 unit tests cover the new helpers (including the colon-target scenarios and the genuine target+config-typo fallback). The existing echo:fail e2e is updated to assert the new message.
  • Verified end-to-end against this repo's CLI with a temporary colon target.

Related Issue(s)

…errors

- When `nx run <project>:<target>` references an unknown target, list up
  to 5 available targets and surface the closest match as 'Did you mean
  ...?'.
- When the project itself is unknown, match the attempted
  `project:target[:configuration]` against every `project:target` task
  id in the graph so project typos (e.g. `webpai:build`) suggest the
  real invocation (`webapi:build`).
- Handle colon-containing target/configuration names: when
  `splitTarget` parses the trailing segment off into a configuration,
  the rejoined specifier is tried first, then progressively shorter
  forms - so `nx:zzcustom:variantt` still suggests `zzcustom:variant`,
  while genuine `target` + `configuration` typos (`biuld:production`
  -> `build`) keep working via the shorter-form fallback.
- New `findClosestMatches` / `findClosestMatch` Levenshtein helper with
  a length-relative threshold (no suggestion for total nonsense).
- Update e2e assertion for the friendlier message.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
@AgentEnder AgentEnder requested a review from a team as a code owner June 3, 2026 02:06
@AgentEnder AgentEnder requested a review from MaxKless June 3, 2026 02:06
@netlify

netlify Bot commented Jun 3, 2026

Copy link
Copy Markdown

Deploy Preview for nx-dev ready!

Name Link
🔨 Latest commit d367664
🔍 Latest deploy log https://app.netlify.com/projects/nx-dev/deploys/6a1fa05abf7e7400088c7c44
😎 Deploy Preview https://deploy-preview-35863--nx-dev.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@netlify

netlify Bot commented Jun 3, 2026

Copy link
Copy Markdown

Deploy Preview for nx-docs ready!

Name Link
🔨 Latest commit d367664
🔍 Latest deploy log https://app.netlify.com/projects/nx-docs/deploys/6a1fa05adddb7300081eb681
😎 Deploy Preview https://deploy-preview-35863--nx-docs.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@nx-cloud

nx-cloud Bot commented Jun 3, 2026

Copy link
Copy Markdown
Contributor

View your CI Pipeline Execution ↗ for commit d367664

Command Status Duration Result
nx affected --targets=lint,test,build,e2e,e2e-c... ✅ Succeeded 15m 23s View ↗
nx run-many -t check-imports check-lock-files c... ✅ Succeeded 3s View ↗
nx-cloud record -- pnpm nx-cloud conformance:check ✅ Succeeded 16s View ↗
nx build workspace-plugin ✅ Succeeded <1s View ↗
nx-cloud record -- nx sync:check ✅ Succeeded 19s View ↗
nx-cloud record -- nx format:check ✅ Succeeded 6s View ↗

☁️ Nx Cloud last updated this comment at 2026-06-03 06:23:08 UTC

nx-cloud[bot]

This comment was marked as outdated.

@nx-cloud nx-cloud Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nx Cloud has identified a flaky task in your failed CI:

🔂 Since the failure was identified as flaky, we triggered a CI rerun by adding an empty commit to this branch.

Nx Cloud View detailed reasoning in Nx Cloud ↗


🎓 Learn more about Self-Healing CI on nx.dev

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant