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

Running nx not at the repository root uses the wrong package manager (npm instead of pnpm) #19831

Closed
4 tasks
sharky98 opened this issue Oct 24, 2023 · 3 comments · Fixed by #27127
Closed
4 tasks
Assignees
Labels

Comments

@sharky98
Copy link

Current Behavior

Using the NX Generator UI from NX Console in WebStorm, I generated a new JS library ([...]/.bin/nx.cmd g @nx/js:library --name=new-name --bundler=esbuild --directory=new-name --minimal=true --projectNameAndRootFormat=as-provided --no-interactive) from my apps directory.

esbuild was not part of my dependencies, so it added it to my package.json file (with the @nx/esbuild).

The generator then tried to install the dependencies using npm install even though I am using pnpm. Obviously, npm install failed ( > NX Command failed: npm install).

It seems that even nx report shows this behavior where is not run from the root, it will not use the right package manager.

Expected Behavior

The generator uses pnpm install in a pnpm repository, no matter which directory nx is run from.

GitHub Repo

No response

Steps to Reproduce

  1. In a pnpm repository, create a workspace.
  2. Run the NX generator where the current working directory is not where package.json and the associated lockfile is.

Nx Report

.repo-root/ > nx report

 >  NX   Report complete - copy this into the issue template
                                                            
   Node   : 20.8.1                                          
   OS     : win32-x64                                       
   pnpm   : 8.9.2                                           
                                                            
   nx (global)        : 17.0.1                              
   nx                 : 17.0.1                              
   @nx/js             : 17.0.1                              
   @nx/eslint         : 17.0.1                              
   @nx/workspace      : 17.0.1                              
   @nx/cypress        : 17.0.1                              
   @nx/esbuild        : 17.0.1                              
   @nx/eslint-plugin  : 17.0.1                              
   @nx/react          : 17.0.1                              
   @nrwl/tao          : 17.0.1                              
   @nx/vite           : 17.0.1                              
   typescript         : 5.2.2

./repo-root/apps > nx report

 >  NX   Report complete - copy this into the issue template

   Node   : 20.8.1
   OS     : win32-x64
   npm    : 10.1.0

   nx (global)        : 17.0.1
   nx                 : 17.0.1
   @nx/js             : 17.0.1
   @nx/eslint         : 17.0.1
   @nx/workspace      : 17.0.1
   @nx/cypress        : 17.0.1
   @nx/esbuild        : 17.0.1
   @nx/eslint-plugin  : 17.0.1
   @nx/react          : 17.0.1
   @nrwl/tao          : 17.0.1
   @nx/vite           : 17.0.1
   typescript         : 5.2.2

Failure Logs

No response

Package Manager Version

No response

Operating System

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

Additional Information

No response

@sharky98 sharky98 changed the title @nx/js:library generator uses wrong package manager to install new dependencies. Running nx not at the repository root uses the wrong package manager (npm instead of pnpm) Oct 24, 2023
@FrozenPandaz FrozenPandaz added the scope: core core nx functionality label Oct 24, 2023
Copy link

This issue has been automatically marked as stale because it hasn't had any recent activity. It will be closed in 14 days if no further activity occurs.
If we missed this issue please reply to keep it active.
Thanks for being a part of the Nx community! 🙏

@github-actions github-actions bot added the stale label Apr 22, 2024
@sharky98
Copy link
Author

Not stale, tested again today with the following this time, from the libs directory.

nx g @nx/js:library --name "test-run-not-root" --directory "libs/shared/test" --bundler=esbuild --minimal=true --projectNameAndRootFormat=as-provided --no-interactive

.repo-root/libs/ > nx report

 NX   Report complete - copy this into the issue template

Node   : 20.10.0
OS     : win32-x64
npm    : 10.5.0

nx (global)        : 18.0.8
nx                 : 18.0.8
@nx/js             : 18.0.8
@nx/eslint         : 18.0.8
@nx/workspace      : 18.0.8
@nx/cypress        : 18.0.8
@nx/devkit         : 18.0.8
@nx/eslint-plugin  : 18.0.8
@nx/plugin         : 18.0.8
@nx/react          : 18.0.8
@nrwl/tao          : 18.0.8
@nx/vite           : 18.0.8
typescript         : 5.4.2
.repo-root/ > nx report

  NX   Report complete - copy this into the issue template

Node   : 20.10.0
OS     : win32-x64
pnpm   : 8.15.4

nx (global)        : 18.0.8
nx                 : 18.0.8
@nx/js             : 18.0.8
@nx/eslint         : 18.0.8
@nx/workspace      : 18.0.8
@nx/cypress        : 18.0.8
@nx/devkit         : 18.0.8
@nx/eslint-plugin  : 18.0.8
@nx/plugin         : 18.0.8
@nx/react          : 18.0.8
@nrwl/tao          : 18.0.8
@nx/vite           : 18.0.8
typescript         : 5.4.2

@github-actions github-actions bot removed the stale label Apr 25, 2024
FrozenPandaz added a commit that referenced this issue Jul 30, 2024
<!-- Please make sure you have read the submission guidelines before
posting an PR -->
<!--
https://github.com/nrwl/nx/blob/master/CONTRIBUTING.md#-submitting-a-pr
-->

<!-- Please make sure that your commit message follows our format -->
<!-- Example: `fix(nx): must begin with lowercase` -->

<!-- If this is a particularly complex change or feature addition, you
can request a dedicated Nx release for this pull request branch. Mention
someone from the Nx team or the `@nrwl/nx-pipelines-reviewers` and they
will confirm if the PR warrants its own release for testing purposes,
and generate it for you if appropriate. -->

## Current Behavior
<!-- This is the behavior we have today -->

The package manager is detected based off of the relative `cwd` which in
most cases is `''`. This incorrectly goes off of the `cwd` of the
command rather than the location of the `package.json` file being
modified.

## Expected Behavior
<!-- This is the behavior we should expect with the changes in this PR
-->

The package manager is detected based off the absolute path of the
directory containing the `package.json` file being modified. So if this
is the root, it will detect the package manager at the root rather than
the `cwd`

## Related Issue(s)
<!-- Please link the issue being fixed so it gets closed when this is
merged. -->

Fixes #19831

(cherry picked from commit 155e69b)
Copy link

This issue has been closed for more than 30 days. If this issue is still occuring, please open a new issue with more recent context.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Aug 26, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants