-
Notifications
You must be signed in to change notification settings - Fork 3.2k
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 resolving wrong binary when using a workspace #6765
Comments
Just a note that I confirmed this bug on both npm 9 and 10. |
The behavior you described does not seem to be a bug in npx, looks more like an intended design based on how npx resolves and executes packages. When you provide the package name explicitly using the If you want to ensure that a specific version of a package is used consistently, you can always use the
This way, you explicitly specify the package to use, and you have control over the version. This can help ensure consistent behavior, especially if you have multiple versions of a package installed in different locations. I don't think it is a bug but rather a feature of npx to provide flexibility in resolving and executing packages. Using the npx will try to execute the locally installed However, when you run npx with |
@siemhesda Your explanation does not make any sense when considering the documentation, which states:
Implying that when I'm not sure the situation you're describing is relevant since you're talking about locally vs globally installed, whereas this issue is about locally installed in workspace vs workspace root. If this is indeed intentional behavior, then the documentation should be updated to reflect this. I challenge you to explain this logic in such a way that it makes sense to the regular user, because I cannot. If I've missed something, please help me out and point to the relevant paragraph for me. |
#6973 fixes this and another bug found while working on this one. npm will now look in the workspace for both the |
@wraithgar Thank you! |
…epos (#27779) # Why If you have a monorepo in which you have different versions of typescript installed you may see that `expo-module build plugin` fails because of unknown TS compiler options. I think it happens because wrong version of `tsc` picked up by `npx`. Related GitHub issues: npm/cli#6765 # How As far as I understand the root cause of this issue is that if we simply run `npx tsc ...` npm does not know `tsc` binary belongs to the `typescript` package and it will simply try to resolve it from the root workspace's `node_modules/.bin` where it will find the wrong version of `tsc` because of dependency hoisting. It should start looking up `tsc` in the workspace's `node_modules/.bin` (from where we're executing `expo-module build plugin`) but that is not the case for some reason. We can only achieve this by giving a hint to `npx` that `tsc` belongs to the package called `typescript`. In this case it will start the binary lookup from the workspace's `node_modules/.bin` folder and use the correct version to build our module plugin. # Test Plan 1. Create a Yarn v2 Berry monorepo. 2. Create a module (`packages/cool-module`) by following the official tutorial **with a config plugin** (https://docs.expo.dev/modules/config-plugin-and-native-module-tutorial/) 3. Add `typescript@^4.5.5` to your workspace root as a dev dependency (or add you could have multiple other workspaces that depend on `typescript@^4.5.5`, e.g. `packages/my-api`) 4. At this point you should see that the 4.5.5 `tsc` is installed in your root `node_modules` and 5.3.0 `tsc` is installed in your `packages/cool-module/node_modules` folder. 5. If you try to run `cd packages/cool-module && yarn run build plugin` you should receive TypeScript config errors since `packages/cool-module/plugin/tsconfig.json` inherits configuration options that are unknown to 4.5.5 `tsc`. (e.g. `"lib": ["es2023"]`). At this point you know something is wrong since `expo-module-scripts` depends on `typescript": "^5.1.3"` that should be aware of `es2023` and `node16` module resolution logic. 6. Go to your module workspace folder (`cd packages/cool-module`) and execute the same command that is executed by `expo-module build plugin` under the hood: `yarn exec -- npx tsc --version`. It should give the **mismatched** `4.5.5` version. 7. Stay in the module workspace folder (`packages/cool-module`) and execute now the following command: `yarn exec -- npx --package=typescript tsc --version`. It should give the **correct** `5.3.0` version. # Checklist - [x] Documentation is up to date to reflect these changes (eg: https://docs.expo.dev and README.md). - [x] Conforms with the [Documentation Writing Style Guide](https://github.com/expo/expo/blob/main/guides/Expo%20Documentation%20Writing%20Style%20Guide.md) - [x] This diff will work correctly for `npx expo prebuild` & EAS Build (eg: updated a module plugin).
Is there an existing issue for this?
This issue exists in the latest npm version
Current Behavior
When using a multi-workspace monorepo, and the same package is present in both the root and a workspace, but with different versions,
npx
without a--package
or--call
argument will resolve the package installed in the root rather than the one in the workspace when using the--workspace
option.Expected Behavior
npx should resolve and execute the package installed in the specified workspace if present.
Steps To Reproduce
As shown above when using the
--package
and/or--call
forms of the command it resolves the correct version of eslint but not with only positional arguments, even though they should be equivalent since the package name and binary name is the same,Environment
The text was updated successfully, but these errors were encountered: