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

CLI binaries from root/node_modules/.bin not found when running package.json scripts of subprojects with Nx #28483

Open
2 of 4 tasks
mklueh opened this issue Oct 17, 2024 · 2 comments
Assignees
Labels
scope: core core nx functionality type: bug

Comments

@mklueh
Copy link

mklueh commented Oct 17, 2024

Current Behavior

Hello, I've migrated my workspace from yarn to pnpm with the hope to get around this issue: wxt-dev/wxt#1058
with success so far.

However, now I'm facing a new problem which I haven't had before, and I'm not sure if it is Nx related, pnpm related or has something to do with the new Node installation (used Vola over NVM to install Node and pnpm).

I'm trying to run a build script from the package.json

  "scripts": {
    "print-env-info": "bash -c 'echo ${SHELL:-/bin/bash}; echo ${LANG:-en_US.UTF-8}; printenv'",
    "build": "nuxt generate" //pnpm nuxt generate also fails
}

and I'm getting this output error

$ pnpm nx run my-app:build

> [email protected] nx C:\Users\MyPc\Workspace\my-project
> nx "run" "my-app:build"


> nx run my-app:build

> [email protected] build C:\Users\MyPc\Workspace\my-project\apps\my-app
> nuxt generate
Der Befehl "nuxt" ist entweder falsch geschrieben oder
konnte nicht gefunden werden.
 ELIFECYCLE  Command failed with exit code 1.

For whatever reason, it is english mixed with german.

When I navigate to apps/my-app in the terminal and run nuxt build it works perfectly.

So it seems Nx has different environment variables than the Git bash I'm using in IntelliJ

To verify that, I've compared the output of running pnpm nx run my-app:print-env-info with running echo ${SHELL:-/bin/bash}; echo ${LANG:-en_US.UTF-8}; printenv manually in the terminal, and indeed, while the Nx command only points to ..../my-project/apps/my-app/node_modules/.bin the manual command from the terminal points to the root node_modules/.bin!

Another observation is that running the script in package.json with IntelliJ's RunConfiguration also fails with the same error.

This issue also appears to happen in GitHub Actions.

  1. Why do / can the environment variables differ?
  2. How can I tell Nx to use the root-level node_modules/.bin for whatever command it executes?

Expected Behavior

To behave identically to the local shell and find the binaries in the submodules

GitHub Repo

No response

Steps to Reproduce

As I have no idea what may influence the environment variables Nx is using (or even the shell) I'd like to get some information first to narrow down the scope

Nx Report

Node : 22.9.0
OS : win32-x64
Native Target : x86_64-windows
pnpm : 9.12.1

nx : 20.0.1
@nx/js : 20.0.1
@nx/jest : 20.0.1
@nx/eslint : 20.0.1
@nx/workspace : 20.0.1
@nx/devkit : 20.0.1
@nrwl/devkit : 19.6.0
@nx/esbuild : 20.0.1
@nx/eslint-plugin : 20.0.1
@nx/express : 20.0.1
@nx/node : 20.0.1
@nx/nuxt : 20.0.1
@nx/playwright : 20.0.1
@nx/vite : 20.0.1
@nx/vue : 20.0.1
@nx/web : 20.0.1
@nx/webpack : 20.0.1
typescript : 5.6.3

Registered Plugins:
@nx/vite/plugin
@nx/eslint/plugin
@nx/playwright/plugin

Community plugins:
@jnxplus/nx-gradle : 1.14.0
@theunderscorer/nx-semantic-release : 2.12.0

The following packages should match the installed version of nx

Failure Logs

No response

Package Manager Version

pnpm latest

Operating System

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

Additional Information

No response

@jaysoo jaysoo self-assigned this Oct 25, 2024
@jaysoo jaysoo added scope: core core nx functionality and removed type: question / discussion labels Oct 25, 2024
@jaysoo
Copy link
Member

jaysoo commented Oct 25, 2024

Hi @mklueh ,

You may need to check your terminal settings in IntelliJ to ensure that it is using git bash, and not something else like powershell. That could be the reason that your environment variables are different. https://www.jetbrains.com/help/idea/settings-tools-terminal.html

For your build script, you could use npx nuxt instead of just nuxt as a workaround.

@mklueh
Copy link
Author

mklueh commented Oct 25, 2024

Hey @jaysoo ,

I'm using Git Bash in IntelliJ already and this shell is aware of the .bin directory.

However it seems nx:run-scripts is then launching CMD instead of the shell it is launched from, which was not aware of the directory. Maybe that's the default shell used by Node.

As a workaround I've added the absolute path to my project's node_modules/.bin to my Windows Environment variables, as bad as that sounds.
It works for me, because I only have one project I'm currently using on my machine.

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

2 participants