Skip to content

nx run -p <project> -t <target:with:colon> crashes instead of running the target #35098

@Stanzilla

Description

@Stanzilla

Current Behavior

When a target name itself contains a :, the flag-based nx run form crashes instead of running the task.

For example, with a project that has a target named test:unit:

nx run -p my-project -t test:unit --outputStyle=static --verbose

fails with:

NX   parsedArgs[PROJECT_TARGET_CONFIG]?.lastIndexOf is not a function

TypeError: parsedArgs[PROJECT_TARGET_CONFIG]?.lastIndexOf is not a function
    at parseRunOneOptions (.../node_modules/nx/src/command-line/run/run-one.js:105:44)

The positional form without escaping is also ambiguous:

nx run my-project:test:unit

That gets interpreted as target test with configuration unit.

The current workaround is to escape the colon in the target name:

nx run my-project:test\:unit

That works, but it is not obvious, and the -p / -t form seems like it should be the unambiguous way to invoke this.

Expected Behavior

This should work:

nx run -p my-project -t test:unit

and run the test:unit target directly.

GitHub Repo

No response

Steps to Reproduce

  1. Create or use any workspace with a project that has a target named test:unit (for example an inferred script target or any custom target with : in its name).
  2. Run:
nx run -p my-project -t test:unit --outputStyle=static --verbose
  1. Observe the TypeError.
  2. Run:
nx run my-project:test\:unit --outputStyle=static
  1. Observe that the target runs successfully.

Nx Report

Node           : 24.14.1
OS             : darwin-arm64
Native Target  : aarch64-macos
pnpm           : 10.33.0
daemon         : Available

nx                     : 22.6.3
@nx/js                 : 22.6.3
@nx/eslint             : 22.6.3
@nx/workspace          : 22.6.3
@nx/devkit             : 22.6.3
@nx/eslint-plugin      : 22.6.3
@nx/module-federation  : 22.6.3
@nx/next               : 22.6.3
@nx/react              : 22.6.3
@nx/rollup             : 22.6.3
@nx/vite               : 22.6.3
@nx/vitest             : 22.6.3
@nx/web                : 22.6.3
@nx/webpack            : 22.6.3
typescript             : 6.0.2

Failure Output

NX   parsedArgs[PROJECT_TARGET_CONFIG]?.lastIndexOf is not a function

TypeError: parsedArgs[PROJECT_TARGET_CONFIG]?.lastIndexOf is not a function
    at parseRunOneOptions (.../node_modules/nx/src/command-line/run/run-one.js:105:44)
    at Object.runOne (.../node_modules/nx/src/command-line/run/run-one.js:24:18)
    at async ...

Notes

I hit this while moving CI jobs to colon-named targets like test:unit and test:storybook.
The escaping workaround is usable, but it feels like nx run -p <project> -t <target-with-colon> should be the supported non-ambiguous form.

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions