Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TypeError in nx:run-commands with env option #23325

Closed
1 of 4 tasks
romainwg opened this issue May 13, 2024 · 1 comment
Closed
1 of 4 tasks

TypeError in nx:run-commands with env option #23325

romainwg opened this issue May 13, 2024 · 1 comment
Assignees
Labels
scope: core core nx functionality type: bug

Comments

@romainwg
Copy link

romainwg commented May 13, 2024

Current Behavior

When executing a custom nx run-command target in nx.json to run a script, specifying environment variables using the "env" option, the command fails with a TypeError: Cannot convert undefined or null to object. This occurs despite following the official documentation for passing environment variables to commands.

For example:

npx nx run default-hmi:docker-build-test

"docker-build-test": {
    "executor": "nx:run-commands",
    "options": {
      "command": "./scripts/docker-manager.sh build",
      "cwd": ".",
      "env": { "FOO": "BAR" }
    }
  }

Expected Behavior

The expected behavior is that the environment variable specified in the "env" option of the nx:run-commands executor should be correctly passed to the command being executed, allowing for successful execution of the script with the provided environment variables. No TypeErrors should occur when using documented features as expected.

The documentation indicates that you can use env or envFile; in fact, envFile works just as well as envFile.
See: https://nx.dev/nx-api/nx/executors/run-commands#env

env is set as object on the json schema:

GitHub Repo

There is no problem on nx 19.0.0-beta (nx-examples):
romainwg/nx-examples-env-issue@4b1d05a

But does not work on nx 18.1.3:
romainwg/nx-examples-env-issue@c45334a

Steps to Reproduce

  1. Define a custom target in nx.json using nx:run-commands that executes a shell script and uses the env option to specify environment variables.
  2. Run the custom target using the Nx CLI command npx nx run <project>:<target>.
  3. Observe the TypeError: Cannot convert undefined or null to object error being thrown during execution.

Nx Report

NX   Report complete - copy this into the issue template

Node   : 21.6.2
OS     : linux-x64
npm    : 10.2.4

nx                 : 18.1.3
@nx/js             : 18.1.3
@nx/jest           : 18.1.3
@nx/linter         : 18.1.3
@nx/eslint         : 18.1.3
@nx/workspace      : 18.1.3
@nx/cypress        : 18.1.3
@nx/devkit         : 18.1.3
@nx/eslint-plugin  : 18.1.3
@nx/node           : 18.1.3
@nx/plugin         : 18.1.3
@nx/react          : 18.1.3
@nx/storybook      : 18.1.3
@nrwl/tao          : 18.1.3
@nx/vite           : 18.1.3
@nx/web            : 18.1.3
typescript         : 5.3.3
---------------------------------------
Community plugins:
@webpro/nx-tsc : 0.0.1
---------------------------------------
Local workspace plugins:
         @hmi/plugin-check-unpinned-dependencies
         @hmi/plugin-check-envs-sync

Failure Logs

TypeError: Cannot convert undefined or null to object
    at Function.keys (<anonymous>)
    (Additional stack trace information corresponding to the error encountered)

Package Manager Version

No response

Operating System

  • macOS
  • Linux
  • Windows
  • Other (Please specify)

Additional Information

No response

@FrozenPandaz FrozenPandaz added the scope: core core nx functionality label May 13, 2024
@xiongemi
Copy link
Collaborator

xiongemi commented May 14, 2024

it is fixed in pr #22426 which is available after 18.2.0. it does not work for 18.1.3. once you update to a version > 18.2.0, it should work.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
scope: core core nx functionality type: bug
Projects
None yet
Development

No branches or pull requests

3 participants