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

workspaces "bin" symlinks not created for sub-dependencies #4964

Open
chrisblossom opened this issue Nov 20, 2017 · 19 comments
Open

workspaces "bin" symlinks not created for sub-dependencies #4964

chrisblossom opened this issue Nov 20, 2017 · 19 comments
Assignees

Comments

@chrisblossom
Copy link

chrisblossom commented Nov 20, 2017

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

What is the current behavior?
Yarn Workspaces do not create node_modules/.bin symlinks for nested dependencies that have a bin specified in their package.json.

Original Yarn issue: #2874

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

Create yarn workspace
Create two workspace packages, one and two
Add two as a dependency to one
Add eslint as a dependency to two

Example: chrisblossom/yarn-issue-4964

What is the expected behavior?
one/node_modules/.bin/eslint symlink exists

Please mention your node.js, yarn and operating system version.
node 8.9.1
Yarn 1.3.2
OSX 10.13.1

@rally25rs
Copy link
Contributor

rally25rs commented Nov 22, 2017

Related: #4543
Caused by #4730

@klaasman
Copy link

Is there a temporary workaround for this issue?

@tothandras
Copy link

@klaasman You can create a symlink to the root node_modules/.bin as a workaround:

$ cd packages/foo
$ mkdir node_modules
$ ln -s ../../../node_modules/.bin ./node_modules

I hope a fix will come soon though... Whenever I switch to yarn I find some blocking bug that forces me to go back to npm.

@alexeyraspopov
Copy link

Another workaround: go back to the root, rm -rf node_modules and do yarn install. This installs everything back and links necessary .bin files to workspaces.

@alexeyraspopov
Copy link

Based on this workaround, it seems that the issue is caused by how PackageLinker works during yarn add in a workspace vs root yarn install. Maybe related to hoisting, @rally25rs?

@alexeyraspopov
Copy link

And worth mentioning, linking does not happen by just yarn install if node_modules are present.

@GAumala
Copy link
Contributor

GAumala commented Jan 18, 2018

Hello, @alexeyraspopov thanks for posting that workaround, it does solve this issue at least partially for me.

I have 4 packages in my workspace, I deleted every single node_modules directory and ran yarn --frozen-lockfile. .bin files are installed for all packages except one. This might be due to the fact that this particular package has only one dependency with a binary, and the workspace has different versions of this package.

Can you please give me any hints on how to debug this by myself? Maybe I should start with src/package-linker.js?

@josh08h
Copy link

josh08h commented Jun 6, 2018

Any movement on this?

Only direct dependencies have their bin symlinked from local node_modules/.bin to the root node_modules/.bin.

> yarn -v
1.7.0

I would expect yarn to symlink all transitive dependency bins and direct dependency bins to the root level node_modules/.bin dir.

@NE-SmallTown
Copy link

Any update on this?

@btakita
Copy link

btakita commented Aug 9, 2018

I had to create a postinstall script that traverses all of the packages*/bin/* files in the repo & symlinks the files into the node_modules/.bin directory.

Of course, I'd love for this bug to be fixed, but here's the hack in the meantime...

#/bin/sh
DIR="$(pwd)"
pushd node_modules/.bin
DIR__BIN="$(pwd)"
# In the case of a git submodule which is also a monorepo
for f in $(find $DIR/packages/*/packages/*/bin/*); do
	ln -sf "$(realpath --relative-to="$(pwd)" "$f")"
done
for f in $(find $DIR/packages/*/bin/*); do
	ln -sf "$(realpath --relative-to="$(pwd)" "$f")"
done
popd

@FezVrasta
Copy link

FezVrasta commented Nov 8, 2018

I'm trying to understand how is Facebook able to use Yarn in production with these bugs... Is anyone from the team aware of this problem? #4730 doesn't seem to have fixed it

sqs added a commit to sourcegraph/sourcegraph-public-snapshot that referenced this issue Nov 10, 2018
This was causing CI failures. The underlying problem appears to be yarnpkg/yarn#4964.
sqs added a commit to sourcegraph/sourcegraph-public-snapshot that referenced this issue Nov 10, 2018
This was causing CI failures. The underlying problem appears to be yarnpkg/yarn#4964.
@mattfysh
Copy link

This seems like the correct behaviour to me. packages/one has not declared a dependency on eslint and therefore should not be given access to the eslint CLI.

If you want to use eslint in the packages/one folder a dependency must be declared. Otherwise you could create a brittle connection between one and the private, internal implementation of two

Can you point to an example of how this works in a non-workspaces setup?

@dizel3d
Copy link

dizel3d commented Jun 16, 2019

nohoist in a root package.json helps me:

"workspaces": {
  "nohoist": [
    "**/eslint"
  ]
},

The same for a child package.json:

"workspaces": {
  "nohoist": [
    "eslint"
  ]
},

@kirill-konshin
Copy link

kirill-konshin commented Oct 2, 2019

If you use Lerna simple trick is to add following to your package.json:

{
  "postinstall": "lerna link"
}

P.S. Side note, keep in mind that after this your monorepo packages will be linked twice (assume packageB requires packageA:

  • node_modules
    • packageA — first link by Yarn
  • packageA — source
  • packageB
    • node_modules
      • packageA — second link by Lerna

@trusktr
Copy link

trusktr commented Feb 16, 2020

@kirill-konshin Interesting. I wonder which sort of symlinking is better? Is the benefit of hoisting only for speed of setup time?

@kirill-konshin
Copy link

@trusktr the thing is that not all tools are smart enough to find the binaries at the top level.

@swernerx
Copy link

swernerx commented Mar 6, 2020

FYI: I build a little tool on top of Lerna to link binaries offered by packages to the top level .bin folder. This makes it possible to use e.g. shared CI tools from a package. (We need this to be implemented that way because other users of the tool outside of the mono repo rely on it as well).

https://github.com/sebastian-software/link-lerna-package-binaries

@eric-burel
Copy link

eric-burel commented May 4, 2022

nohoist seems deprecated but the replacing options doesn't give enough control: https://yarnpkg.com/configuration/manifest#installConfig

Any other hint on this? I have a Remix starter in a monorepo and I rely a lot on their CLI, it must stay in the right node_modules

Edit: I've configure my starter app package.json like so:

"installConfig": {
    "hoistingLimits": "dependencies"
  }

This way, I use hoisting for my packages (I have a depcheck to confirm that I didn't miss a dependency before deploying) but I disable it for the Remix starter up, it seems to work ok this way.

I still need to figure how to use the "plug and play" mode to avoid node_modules, if that's even possible.

This works better, however then running binaries with yarn in the starter/remix folder, seems to actually run it at the root. So for instance, yarn run-p will look for scripts at the root package.json level and not at the remix package.json level.

istarkov added a commit to webstudio-is/webstudio that referenced this issue Nov 25, 2022
- [x] - Image optimization component moved into standalone package
- [x] - generate-arg-types moved into standalone package - one issue
with current yarn yarnpkg/yarn#4964 (you need
to delete root node_modules, then yarn and yarn build to make
generate-arg-types to work)
- [x] - move json into `__generated__` folder, (allow import json from
__generated__ folders only)
- [x] - Icons moved all gen into `__generated__`
- [x] - css-data generated content moved to `__generated__`
@kenfj
Copy link

kenfj commented Jun 20, 2024

FYI: I've encountered similar issue like yarn dev should call vite but got command not found: vite
because node_modules/.bin hasn't been created in some of sub-packages.

In my case, I added "@types/node": "^18.8.4", in the devDependencies and it worked 🎉

I have no idea why this worked but I found @types/node was missing in the not-working sub-packages by comparing other working sub-packages in the same workspaces.

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

No branches or pull requests