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?
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
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?
Is it possible that I installed a gem that provided
yarnsome 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.
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.
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.
You can also copy ./bin/yarn to ./bundle/bin/yarn inside your rails app and keep rbenv-binstubs
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.
@akashani62 you have a typo in your comment: it should be .bundle/bin/yarn (without the first slash!).
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.
Anyone who wants to use rbenv-binstubs and do not want to deal with incorrect shims please check this comment: https://github.com/ianheggie/rbenv-binstubs/issues/29#issuecomment-404487285
This should be resolved in madumlao/rbenv-binstubs@335a8301295f568d8dea288726a28e04ad5660ac (master branch): rbenv-binstubs will now only shim / inject ruby executables.
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.
@PatrickDePuydt, unless your rbenv-binstubs distinguishes between ruby and non-ruby executables, yarn will get picked up again on your next rehash.
You can also copy
./bin/yarnto./bundle/bin/yarninside your rails app and keeprbenv-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?
@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).
@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

@waruboy
But I just want to make sure if this is expected. When i run
which yarncommand 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.
@madumlao got it and confirmed! Thanks for your kind explanation
Most helpful comment
The
yarnshim was added to rbenv because one of the Ruby versions has, for some reason, ayarnexecutable. To remove it, do the following in bash: