Skip to content
This repository has been archived by the owner on Jul 9, 2024. It is now read-only.

[BUG] Running NX command is not working with pnpm #40

Closed
robinpellegrims opened this issue Mar 11, 2022 · 3 comments · Fixed by #44
Closed

[BUG] Running NX command is not working with pnpm #40

robinpellegrims opened this issue Mar 11, 2022 · 3 comments · Fixed by #44
Labels
bug Something isn't working good first issue Good for newcomers

Comments

@robinpellegrims
Copy link
Contributor

robinpellegrims commented Mar 11, 2022

I'm submitting a...


[X] Regression (a behavior that used to work and stopped working in a new release)
[ ] Bug report  
[ ] Performance issue
[ ] Feature request
[ ] Documentation issue or request
[ ] Support request
[ ] Other... Please describe:

Current behavior

I'm using pnpm as package manager and it always worked perfectly in the past. Currently e-square-io/nx-distributed-task fails with the following error:

🏃 Running NX target
  /home/runner/setup-pnpm/node_modules/.bin/pnpm exec -p @nrwl/cli nx run-many --projects=markdown --skip-nx-cache=false --target=test --parallel=3
  undefined
   ERR_PNPM_RECURSIVE_EXEC_FIRST_FAIL  not found: -p
Error: Error: The process '/home/runner/setup-pnpm/node_modules/.bin/pnpm' failed with exit code 1

The command also fails locally, as "pnpm exec" doesn't have a flag -p. (https://pnpm.io/cli/exec)

// this fails
$ pnpm exec -p @nrwl/cli nx run-many ---projects=markdown --target=test --parallel=3
 ERR_PNPM_RECURSIVE_EXEC_FIRST_FAIL  not found: -p

// this works
$ pnpm exec nx run-many --projects=markdown --target=test --parallel=3
 
 >  NX   Running target test for 1 project

Last known version that worked without any issues: v2.2.6. In this version, the run-many command was different:
/home/runner/setup-pnpm/node_modules/.bin/nx run-many --projects=markdown --target=test --parallel --maxParallel=3

Expected behavior

It should continue to work with pnpm.

Minimal reproduction of the problem with instructions

Create a github action on a repository and install pnpm:

    - name: Install and execute pnpm
      uses: pnpm/[email protected]
      with:
        version: 6.32.3
        run_install: |
          - args: [--frozen-lockfile, --prefer-offline]

Use the latest version of e-square-io/nx-distributed-task to execute the tasks.

      - name: Execute
        uses: e-square-io/[email protected]

Environment

- Nx version: 13.8.7
- Platform:  Linux
@ronnetzer ronnetzer added bug Something isn't working good first issue Good for newcomers labels Mar 15, 2022
@ronnetzer
Copy link
Member

Hi @robinpellegrims

Thank you for reporting the issue, would you like to contribute and fix it?
It should be pretty easy, the changes are only in nx-distributed-file/src/app/nx.ts file in nxCommand method

...
const wrapper = exec
  .withCommand(`${command} -p @nrwl/cli nx ${nxCommand}`)
...

the extra -p @nrwl/cli arguments should move to be part of the command if the package manager is npm.

It should be checked what is the equivalent for each package manager

extra info:
the actions uses getPackageManagerCommand from NX to retrieve the commands for the relevant package manager.
for npm its npx
for yarn its yarn
and for pnpm its pnpx and above v6.13 its pnpm exec
Apparently NX is not checking if yarn 2 is being used which doesn't have the list command (it uses a different info command) so we'll need to add a check for yarn's version and to adjust the command accordingly.

Also, what about asserting that NX is installed? does this step works as expected? I assume so as your error is after this step but just to make sure.

@ronnetzer ronnetzer changed the title Not working anymore with pnpm [BUG] Running NX command is not working with pnpm Mar 15, 2022
@robinpellegrims
Copy link
Contributor Author

robinpellegrims commented Mar 15, 2022

Sure, I'll take a look.

The assertNxInstalled did work because it was hardcoded to use npm instead of pnpm, but it seems you fixed that today to use the installed package manager instead.

Also, it seems that the actual equivalent of npx -p @nrwl/cli is pnpm --package @nrwl/cli dlx. Should we go down that road or stay close to what nx is returning in getPackageManagerCommand ?

@ronnetzer
Copy link
Member

@robinpellegrims let's stay close to what NX returns

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working good first issue Good for newcomers
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants