question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. ItΒ collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

`nx start <app> --args='<args>'` works in a counter-productive way

See original GitHub issue

Nx (and @nrwl/workspace:run-commands specifically) seems to do some extremely strange and counter-productive things with the command-line args that are meant to be passed to the primary target as-is.

Context

Our use case is a command-line app (say placed under apps/cli) that depends on various libraries under libs/. Whenever we run yarn nx start cli, we want nx to check if the cli app needs to be built first and in that case it should run the build target for it and all of its dependencies.

This works well and is accomplished via the following configuration in nx.json:

  ...
  "targetDependencies": {
    "start": [
      {
        "target": "build",
        "projects": "self"
      }
    ],
    "build": [
      {
        "target": "build",
        "projects": "dependencies"
      }
    ],
  ...

After building (if needed) we want all CLI args (let’s signify them by ...), specified via either yarn start cli --args='...' or yarn start cli -- ..., to be passed without modification only to the start target of the cli app:

apps/cli/project.json:

  ...
    "start": {
      "executor": "@nrwl/workspace:run-commands",
      "options": {
        "command": "node apps/cli/dist/main.js"
      }
    },
  ...

In other words, the command executed for the start target should be:

node apps/cli/dist/main.js ...

Current Behavior

Nx transmogrifies the CLI args after which it passes them to the commands triggered from the build targets the libraries that the cli app depends on.

For example, if we run yarn nx start cli --args='--option1 --option2', nx will need to solve the following target dependency graph:

  • apps/cli:start ->
    • apps/cli:build ->
      • libs/lib1:build ->
        • libs/lib1:build-part-1 ->
          • libs/lib1:codegen ->
        • libs/lib1:build-part-2 ->
          • libs/lib1:codegen ->

Which yields the following topological ordering (assuming synchronous/linear execution, not parallel, for simplicity):

  1. libs/lib1:codegen (executor: @nrwl/workspace:run-commands)
  2. libs/lib1:build-part-1
  3. libs/lib1:build-part-2
  4. libs/lib1:build (executor: @nrwl/workspace:run-commands)
  5. apps/cli:build
  6. apps/cli:start (executor: @nrwl/workspace:run-commands)

Instead of simply running the commands specified by targets 1., 4. and 6., Nx (via yargs) first transforms --option1 --option2 to --_= --option1=true --option2=true and appends it to the command string of targets 1, 4 and 6, which causes them to fail.

Expected Behavior

Given command:

yarn nx start cli --args='--option1 --option2'

and topological ordering:

  1. libs/lib1:codegen (executor: @nrwl/workspace:run-commands)
  2. libs/lib1:build-part-1
  3. libs/lib1:build-part-2
  4. libs/lib1:build (executor: @nrwl/workspace:run-commands)
  5. apps/cli:build
  6. apps/cli:start (executor: @nrwl/workspace:run-commands)

Nx should pass --option1 --option2 only to target 6.

Steps to Reproduce

Let me know if the information provided is sufficient. If not, I can prepare a repo that reproduces the problem.

Failure Logs

➀ yarn nx start cli --args='--option1 --option2'

 >  NX   Running target start for project cli and 5 task(s) it depends on

 β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”

> nx run lib1:code-gen --args="--option1 --option2"

Error occured:  Unknown option: --_=
Run with --show-stack-traces to see the full stacktrace
ERROR: Something went wrong in @nrwl/run-commands - Command failed: command --_= --option1=true --option2=true

 β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”

 >  NX   Running target "cli:start" failed

   Failed tasks:
   
   - lib1:code-gen
   
   Hint: run the command with --verbose for more details.

Environment

➀ yarn nx report

 >  NX   Report complete - copy this into the issue template

   Node : 16.13.2
   OS   : linux x64
   yarn : 3.1.1
   
   nx : 13.8.4
   @nrwl/angular : undefined
   @nrwl/cli : 13.8.4
   @nrwl/cypress : 13.8.4
   @nrwl/detox : undefined
   @nrwl/devkit : 13.8.4
   @nrwl/eslint-plugin-nx : 13.8.4
   @nrwl/express : 13.8.5
   @nrwl/jest : 13.8.4
   @nrwl/js : 13.8.4
   @nrwl/linter : 13.8.4
   @nrwl/nest : undefined
   @nrwl/next : 13.8.4
   @nrwl/node : 13.8.4
   @nrwl/nx-cloud : undefined
   @nrwl/react : 13.8.4
   @nrwl/react-native : undefined
   @nrwl/schematics : undefined
   @nrwl/storybook : 13.8.4
   @nrwl/tao : 13.8.4
   @nrwl/web : 13.8.4
   @nrwl/workspace : 13.8.4
   typescript : 4.5.5
   rxjs : 7.5.5
   ---------------------------------------
   Community plugins:

Issue Analytics

  • State:open
  • Created 2 years ago
  • Reactions:1
  • Comments:6

github_iconTop GitHub Comments

2reactions
akolleggercommented, May 20, 2022

I’ve worked around this by wrapping the desired command args in a nested args which is then interpolated in place.

A target for running oclif:

    "exec": {
      "executor": "nx:run-commands",
      "outputs": [],
      "options": {
        "command": "bin/run {args.args}",
        "cwd": "apps/oclif"
      }
    }

Nesting the args by calling like this:

nx run oclif:exec --args="--args='help plugins'"
1reaction
Rijak0commented, Nov 28, 2022

What worked for me with version 14.8.3: yarn nx start cli --args=--option1,--option2

Read more comments on GitHub >

github_iconTop Results From Across the Web

@nrwl/workspace:run-commands | Nx
Chaining commands, interpolating args and setting the cwd. Let's say each of our workspace projects has some custom bash scripts in a scripts...
Read more >
NX Classic Toolbar User Interface Will Retire from Windows in ...
I found the way how to set up the classic UI even in Daimler environment, where the simple way to switch to classic...
Read more >
Need help in controlling robot orientation in grinding application.
I'm using Robot machining project in RoboDK and the configuration is "Robot holds object". And I've tried setting path to tool offset but...
Read more >
Deploying Nx workspace to Google App Engine - Stack Overflow
I am using Nx@13, here are steps to deploy to GAE: Add "generatePackageJson": true, to production executor, it will generate a package.jsonΒ ...
Read more >
HAProxy version 1.8.30 - Configuration Manual - GitHub Pages
Some parameters involve values representing time, such as timeouts. ... allow a buggy application to work by the time it gets fixed.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found