Skip to content

Updating a package that depends on yarn globally will override system yarn #7132

@ahmedelgabri

Description

@ahmedelgabri

This is not an issue with yarn itself, but a current issue faced oclif/plugin-plugins#71 which is a dependency of netlify/cli#269

When yarn installs global packages they usually symlink global node_modules/.bin to /usr/local/bin so if you install a global package that depends on yarn, yarn will override the system installed yarn with the node_module/.bin/yarn one.

I can see this issue starting to get bigger after yarn v2 is released too.

This might be related to #2627, #3157

So is there is any workaround? Also how can this be prevented?

Not 100% sure but npm might also have this if npm is a dependency of a package too

Thanks to @bk3c, he managed to reproduce the issue (see oclif/plugin-plugins#71 (comment)) & I also confirm that this is the case for me too.

FWIW, I've been struggling with the effects of this for a few months, and finally figured it out enough to find this issue. I'm pretty sure I have a reproducible case, though I can't tell if this is actually yarn being broken or misused:

  • my system yarn is via homebrew
  • I have two globally installed packages that depend on this one (apollo and netlify-cli), and this is the only global dependency I have on yarn
  • if I wipe my global yarn.lock and node_modules and reset all of the symlinks, I can do a yarn add to recreate both with no problems at all
  • as soon as I do a yarn global upgrade or yarn global upgrade-interactive, the symlinks in /usr/local/bin are overwritten and now point to ~/.config/yarn/global/node_modules/.bin/yarn
  • this is 100% reproducible, at least in my environment
  • it's super-annoying

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions