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

yarn bin points to incorrect path when package is scoped inside workspace. #8926

Open
francoisgergaud opened this issue Feb 20, 2023 · 1 comment

Comments

@francoisgergaud
Copy link

francoisgergaud commented Feb 20, 2023

Do you want to request a feature or report a bug?

Bug

What is the current behavior?

When yarn generate the cmd file for a executable defined in the bin section of the package.json, the path to the executable is set incorrectly as the scope folder is not in the path.

[4/4] Building fresh packages...
error C:<my workspace root>\node_modules\packageA: Command failed.
Exit code: 1
Command: yarn packageBUtil --verbose
Arguments:
Directory: C:<my workspace root>\node_modules\packageA
Output:
yarn run v1.22.19
$ C:<my workspace root>\node_modules\packageA\node_modules.bin\packageBUtil --verbose
node:internal/modules/cjs/loader:936
throw err;
^

Error: Cannot find module 'C:<my workspace root>\node_modules\packageB\src\utility.js'
at Function.Module._resolveFilename (node:internal/modules/cjs/loader:933:15)
at Function.Module._load (node:internal/modules/cjs/loader:778:27)
at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:77:12)
at node:internal/main/run_main_module:17:47 {
code: 'MODULE_NOT_FOUND',
requireStack: []
}
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

The path of the bin should be 'C:<my workspace root>\node_modules\@scope\packageB\src\utility.js', not 'C:<my workspace root>\node_modules\packageB\src\utility.js' .

If the current behavior is a bug, please provide the steps to reproduce.

All the steps described bellow are already available by cloning the following repository: https://github.com/francoisgergaud/debug-yarn-workspaces-bin/tree/main

  1. create a package with a workspace
  2. create 2 packages inside the workspaces folder, packageA and packageB. The packages must be scoped.
  3. Add an nodeJS file with the #!/usr/bin/env node shebang in packageB, add a command in the bin section of the package.json
  4. Add a dependency from packageA to packageB and call the command from packageB in the preinstall lifecycle script.
  5. run yarn from the root folder. It will fail saying the nodeJS file from packageB is not found when packageA calls it.

Please mention your node.js, yarn and operating system version.

Yarn 1.22.19, Node 16.18, Windows 10 x64 (we are stuck with yarn classic on our project).

Other:

It works when packageB is not scoped (the scope prefix is removed from the package's name, see https://github.com/francoisgergaud/debug-yarn-workspaces-bin/tree/without-scope). It also works on Linux with the scope prefix in the package's name.

@francoisgergaud francoisgergaud changed the title yarn bin path incorrect when package is scoped yarn bin points to incorrect path when package is scoped inside workspace. Feb 20, 2023
@francoisgergaud
Copy link
Author

I guess this is related to #4564, but not 100% sure.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant