asdf
asdf copied to clipboard
bug: error for missing shim version is confusing
Describe the Bug
I am trying to move my team to asdf. One of my coworkers encountered this error, which is somewhat cryptic (and incorrect). Maybe we can improve it?
Thanks for creating such a great project, we love asdf!
Steps to Reproduce
- Setup .tool-versions with nodejs
asdf install. Yarn is not yet installed (for that version of nodejs).yarn -vto get the error
Expected Behaviour
Can we improve the error message? Perhaps something more like:
asdf is using nodejs 14.17.0 in this directory. You tried to run yarn, but yarn is not
installed for this version of nodejs. Here are a couple of ways to fix this issue:
(1) Install yarn for nodejs 14.17.0.
(2) Maybe you installed yarn in a different version of nodejs? Try switching this
directory to another version of nodejs.
Actual Behaviour
No preset version installed for command yarnpkg
Please install a version by running one of the following:
asdf install nodejs 14.17.0
or add one of the following versions in your config file at /Users/nathan/.tool-versions
nodejs 16.13.2
Environment
OS:
Darwin xxx.local 20.6.0 Darwin Kernel Version 20.6.0: Mon Aug 30 06:12:20 PDT 2021; root:xnu-7195.141.6~3/RELEASE_ARM64_T8101 arm64
SHELL:
zsh 5.8 (x86_64-apple-darwin20.0)
ASDF VERSION:
v0.9.0
ASDF ENVIRONMENT VARIABLES:
ASDF_DIR=/opt/homebrew/Cellar/asdf/0.9.0/libexec
ASDF INSTALLED PLUGINS:
nodejs [email protected]:asdf-vm/asdf-nodejs.git master ed34355
asdf plugins affected (if relevant)
No response
+1
This error is still occurring. Any help or update is appreciated 🙏
- Running:
npm install -g yarnreturnsnpm ERR! File exists: ~/.asdf/installs/nodejs/18.12.1/bin/yarn - I can see
yarnandyarnpkgoncding to that location - And it is the latest version (
v3.3.1) - Looking up the available shims in
~/.asdf/shimsshows that the yarn shims are not there.
To solve this I think ~/.asdf/shims should have an entry for yarn.
Update: I ran the following commands which seem to have solved my issue
> asdf exec yarn -v
unknown command: yarn. Perhaps you have to reshim?
> asdf reshim nodejs 18.12.1
> which yarn
~/.asdf/shims/yarn
> cd back to folder with correct .tool-versions
> which yarn
~/.asdf/shims/yarn
> yarn -v
3.3.1
In summary, I installed the latest stable nodejs, and followed the instructions to setup yarn (using corepack), but the yarn executable was missing from the path. The problem was that the yarn executable wasn't shimmed properly when I installed the new version of nodejs.
https://asdf-vm.com/more/faq.html#newly-installed-executable-not-running
https://asdf-vm.com/manage/core.html#reshim
We generally recommend against installing globally managed tools via asdf managed runtimes or tools. asdf -> nodejs -> yarn means that whenever you change nodejs version, you would need to reinstall yarn or capture the shim of the global in the new nodejs version. In these cases, it is best to manage that global tool in asdf itself. There is an asdf plugin for yarn.
We have documentation covering this scenario.
Your suggested output is certainly much clearer. The problem here is that this error message is not built in one place in the codebase, but rather built-up throughout the codebase from various other calls so it is a harder to implement than a simple text change.
We can look into this though.