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

[BUG] Npx executes wrong version of dependency present in several workspaces #6276

Closed
2 tasks done
bertrandE opened this issue Mar 21, 2023 · 3 comments
Closed
2 tasks done
Labels
Bug thing that needs fixing Needs Triage needs review for next steps Release 8.x work is associated with a specific npm 8 release

Comments

@bertrandE
Copy link

Is there an existing issue for this?

  • I have searched the existing issues

This issue exists in the latest npm version

  • I am using the latest npm

Current Behavior

Suppose that you need a dependency (eg. eslint) in different versions in two workspaces (eg. childA and childB):

$ npm ls eslint
├─┬ [email protected] -> ./packages/childA
│ └── [email protected]
└─┬ [email protected] -> ./packages/childB
  └── [email protected]
  • execute npx -w packages/childA and in the interactive subshell execute eslint -v. It returns v8.36.0 as expected
  • execute npx -w packages/childB and in the interactive subshell execute eslint -v. It returns v7.32.0 as expected
  • execute npx -w packages/childB eslint -v. It returns v8.36.0 (expected v7.32.0)

Is this intended behaviour? Am I missing something when using npx in the context of workspaces?

Expected Behavior

I expected npx -w packages/childB eslint -v to return the eslint version relative to the childB workspace (ie. v7.32.0).

Steps To Reproduce

Using the following repo https://github.com/bertrandE/npm-repro-bin-child-workspace
Execute the commands specified in "Current Behavior".

Somewhat related issue: #2826

Environment

Tested on both NPM 8 and NPM 9.

@bertrandE bertrandE added Bug thing that needs fixing Needs Triage needs review for next steps Release 8.x work is associated with a specific npm 8 release labels Mar 21, 2023
@tnorling
Copy link

I am also experiencing this, but only on Windows. It appears to be working as expected on Linux.

@wertlex
Copy link

wertlex commented Jun 27, 2023

The same here, however, when pulling referenced repo and performing npm i in root folder (npm ci not works because js-yaml-3.14.1 could not be resolved) everything seems to work in a right way.

However, if installing eslint step by step in each package, the issue will be reproduced.
Summarizing to one command:

rm -rf ./package-lock.json && \
cd ./packages/childA && \
npm rm eslint && \
cd ../../packages/childB && \
npm rm eslint && \
npm i -D -E [email protected] && \
cd ../../packages/childA && \
npm i -D -E [email protected] && \
cd ../../

An interersting thing here that it looks like that npx uses only eslint which was hoisted to repo root. So, in this case if one will change of order of npm i -D -E eslint..., result will be different.

Tested with node:18.16.1 docker image

@milaninfy
Copy link
Contributor

@bertrandE This could be fixed on latest version of npm. PR: #7379
Running on 10.8.1 it's working as expected.

~/workarea/rep/test $ npm ls
[email protected] /Users/milaninfy/workarea/rep/test
├─┬ [email protected] -> ./a
│ └── @bintest/[email protected]
└─┬ [email protected] -> ./b
  └── @bintest/[email protected]

~/workarea/rep/test $ npx -w a @bintest/pkg1
Current time: 6/21/2024, 4:41:56 PM
Package name: @bintest/pkg1
version: 1.0.0
~/workarea/rep/test $ npx -w b @bintest/pkg1
Current time: 6/21/2024, 4:42:02 PM
Package name: @bintest/pkg1
version: 3.0.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug thing that needs fixing Needs Triage needs review for next steps Release 8.x work is associated with a specific npm 8 release
Projects
None yet
Development

No branches or pull requests

5 participants
@wertlex @tnorling @bertrandE @milaninfy and others