asdf-vm / asdf-nodejs

Node.js plugin for asdf version manager
https://github.com/asdf-vm/asdf
MIT License
886 stars 141 forks source link

asdf suggests nodejs version is not installed when actually yarn isn't #392

Closed nealeu closed 1 month ago

nealeu commented 4 months ago

In migrating from nodejs 16 to 18, I get the following when trying to run a yarn command (e.g. yarn -v)

$ yarn -v
No preset version installed for command yarn
Please install a version by running one of the following:

asdf install nodejs 18.19.0

or add one of the following versions in your config file at /home/neale/dev/ecco/ecco/.tool-versions
nodejs 16.20.2

This is despite having done as instructed.

The issue was in fact that under nodejs 16, I have yarn installed and there is a yarn shim, but under nodejs 18, I don't have yarn installed.

Doing npm -g install yarn resolves the above error.

allisonphillips commented 1 month ago

Try npm install -g yarn from the terminal window where you're attempting to run yarn -v. The error message is telling you that the only version of yarn that asdf has shimmed is for nodejs 16.20.2; your current context appears to be running nodejs 18.19.0, so you need to run the install command in this new context to install a version of the yarn package that is compatible with the different version of node used by that context (18.19.0). See my comment for more.

augustobmoura commented 1 month ago

@allisonphillips is correct, yarn is not automatically installed on each version. In older versions yarn was distributed inside NodeJS tarballs. Nowadays yarn is packaged within corepack, so you need to enable it first:

corepack enable
asdf reshim nodejs

I just merged a new functionality to enable corepack automatically on new installations, just set the ASDF_NODEJS_AUTO_ENABLE_COREPACK to anything on your shell's rc file and it should be good to go