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 shim can't seem to find installed yarn #1051

Closed
bunnymatic opened this issue Nov 28, 2017 · 18 comments
Closed

yarn shim can't seem to find installed yarn #1051

bunnymatic opened this issue Nov 28, 2017 · 18 comments

Comments

@bunnymatic
Copy link

I've had this problem for a bit. It seems that rbenv can't seem to figure out where yarn is. I realize it's a js dependency so i'm not quite sure why rbenv even wants to have a shim for it.

I'm in a directory that is a JS only project - so there is no .ruby-version, i have the following config:

$ rbenv --version
rbenv 1.1.0
$ ruby --version
ruby 2.4.0p0 (2016-12-24 revision 57164) [x86_64-darwin15]
$ brew list
...
yarn
...
$ which yarn
/Users/jon/.rbenv/shims/yarn
$ yarn -v
rbenv: yarn: command not found
$ brew list yarn
/usr/local/Cellar/yarn/1.2.1/bin/yarn
/usr/local/Cellar/yarn/1.2.1/bin/yarnpkg
/usr/local/Cellar/yarn/1.2.1/libexec/bin/ (5 files)
/usr/local/Cellar/yarn/1.2.1/libexec/lib/ (2 files)
/usr/local/Cellar/yarn/1.2.1/libexec/package.json
$ /usr/local/bin/yarn -v
1.2.1

This has also occurred in ruby project directories where there is a .ruby-version and I'm using yarn for webpack and other stuff.

Any ideas?

@mislav
Copy link
Member

mislav commented Nov 29, 2017

The yarn shim was added to rbenv because one of the Ruby versions has, for some reason, a yarn executable. To remove it, do the following in bash:

for ver in $(rbenv whence yarn); do
  RBENV_VERSION="$ver" gem uninstall -ax yarn
  rm -f "$(rbenv prefix "$ver")/bin/yarn"
done
rbenv rehash

# now check the yarn executable again:
which -a yarn

@bunnymatic
Copy link
Author

This didn't do anything for me. I did some more digging and rbenv whence yarn gave me nothing.
It also gave me nothing when I was in a ruby directory that included a gem (rails 5.1.0.rc) that had yarn in it. So I'm confused about how that should work?

Because I was in a project dir with no ruby-version file, the shims used are the system shims, right?
In my report above it's clearly trying shims from my home dir /Users/jon/.rbenv/shims/. Is it possible that I installed a gem that provided yarn some time in the past and then removed it (from the global set) but the shim did not get removed?

@mislav
Copy link
Member

mislav commented Dec 4, 2017

Is it possible that I installed a gem that provided yarn some time in the past and then removed it (from the global set) but the shim did not get removed?

That is definitely possible. But if rbenv whence yarn doesn't return any results, then yarn should be gone from /Users/jon/.rbenv/shims/ automatically on next rbenv rehash (and also, by default, each time you spawn a new shell session). Unless you have some rbenv plugins that I don't know about.

@bunnymatic
Copy link
Author

Thanks for the info. I'm pretty sure it's something about my setup. If I find a solution, I can add notes to the ticket.

@0xBADDCAFE
Copy link

Unless you have some rbenv plugins that I don't know about.

I faced this problem too and check installed plugins. I removed https://github.com/ianheggie/rbenv-binstubs and solved it.

@akashani62
Copy link

You can also copy ./bin/yarn to ./bundle/bin/yarn inside your rails app and keep rbenv-binstubs

@0xBADDCAFE
Copy link

You can also copy ./bin/yarn to ./bundle/bin/yarn inside your rails app and keep rbenv-binstubs

In my environment, this happens not only rails project directory but anywhere globally.

@morgler
Copy link

morgler commented May 30, 2018

@akashani62 you have a typo in your comment: it should be .bundle/bin/yarn (without the first slash!).

@tsujigiri
Copy link

Is it possible that I installed a gem that provided yarn some time in the past and then removed it (from the global set) but the shim did not get removed?

I encountered something similar with a different executable. One of the projects I work with has a dependency that adds an executable to the shims of the same name as a system one. When I switch from that project to another one, that uses the system wide executable, I get confused about the errors regularly, until I remember to delete the shim. Not sure how to fix this other than working on consistency between projects, but that's not always an option.

@mrhead
Copy link

mrhead commented Jul 12, 2018

Anyone who wants to use rbenv-binstubs and do not want to deal with incorrect shims please check this comment: Purple-Devs/rbenv-binstubs#29 (comment)

@madumlao
Copy link

madumlao commented Aug 6, 2018

This should be resolved in madumlao/rbenv-binstubs@335a830 (master branch): rbenv-binstubs will now only shim / inject ruby executables.

@PatrickDePuydt
Copy link

PatrickDePuydt commented Nov 26, 2018

For what it's worth, I was able to fix this issue by running rm -rf /Users/$(whoami)/.rbenv/shims/yarn. Don't know if that's recommended but I tried everything here and nothing worked.

@madumlao
Copy link

@PatrickDePuydt, unless your rbenv-binstubs distinguishes between ruby and non-ruby executables, yarn will get picked up again on your next rehash.

@waruboy
Copy link

waruboy commented Feb 7, 2019

You can also copy ./bin/yarn to ./bundle/bin/yarn inside your rails app and keep rbenv-binstubs

only this works for me.
running
bundle install --binstubs .bundle/bin does not work

@madumlao do you have some clue about how that is so?

@madumlao
Copy link

@waruboy, have you tried forcing a rbenv rehash and rehash on your shell after the bundle? It may be that your shell used the old path after running bundle install --binstubs .bundle/bin and this was not picked up by the which command.

As an update, I've also tried a different approach in madumlao/rbenv-binstubs/unshadow . This is also merged in madumlao/rbenv-binstubs/master

rbenv-binstubs will now actively "unshim" if no binstubs are pointed to by any shimmed executables, thus defaulting to whatever system or user-defined paths are defined.

This should solve the case where yarn being shimmed inside the project path of one ruby project causes yarn to break everywhere else (rbenv will not use the shim if the yarn executable pointed to by the shim does not exist). However, inside the project path of that ruby project, the yarn shim will still be used. This does not resolve any issues caused by that yarn shim being broken (if it is broken).

@waruboy
Copy link

waruboy commented Feb 24, 2019

@madumlao thank you for your response. I pulled your latest master and it works!

But I just want to make sure if this is expected. When i run which yarn command in non-ruby / non-bundler directory, it will still point to rbenv shims:

taufiqm@taufiq-rig:~$ cd empty-dir/
taufiqm@taufiq-rig:~/empty-dir$ ls
taufiqm@taufiq-rig:~/empty-dir$ which yarn
/home/taufiqm/.rbenv/shims/yarn
taufiqm@taufiq-rig:~/empty-dir$ yarn -v
1.13.0

selection_029

@madumlao
Copy link

@waruboy

But I just want to make sure if this is expected. When i run which yarn command in non-ruby / non-bundler directory, it will still point to rbenv shims

Yes, that is expected behavior. You will notice though, that if you run rbenv which yarn, the yarn will be pointed back to your system yarn (if there is one) or otherwise yarn from nenv or similar environment manager.

@waruboy
Copy link

waruboy commented Feb 24, 2019

@madumlao got it and confirmed! Thanks for your kind explanation

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

10 participants