bug: tool installed in global nodejs are not available in project with a different nodejs version
sblask opened this issue · 4 comments
Describe the Bug
I've got a global .tool-versions file:
python 3.11.7
nodejs 20.11.0
rust 1.73.0
...
and installed typescript-language-server into it:
~ $ which tsserver
/Users/sebastianblask/.asdf/shims/tsserver
~ $ tsserver
Content-Length: 76
{"seq":0,"type":"event","event":"typingsInstallerPid","body":{"pid":74072}}
In one of my projects I've got this in my .tool-versions:
nodejs 18.19.1
and tsserver is not available:
$ tsserver
No preset version installed for command tsserver
Please install a version by running one of the following:
asdf install nodejs 18.19.1
or add one of the following versions in your config file at /Users/sebastianblask/Code/project/.tool-versions
nodejs 20.11.0
When I change my /Users/sebastianblask/Code/project/.tool-versions to:
nodejs 18.19.1 20.11.0
tsserver works, but I don't think this should be necessary? It's also no desirable because the global .tool-versions is specific to my setup and I don't want to force the versions in there onto the people that work on the project.
Steps to Reproduce
See description ^
- install one node version globally
- npm install -g typescript-language-server
- go into another folder
- install another node version
- try to run tsserver
- it's not working
Expected Behaviour
asdf should fall back to global nodejs automatically
Actual Behaviour
asdf gives workaround instead of it just working
Environment
$ asdf info
OS:
Darwin Sebastians-MacBook-Pro.local 23.3.0 Darwin Kernel Version 23.3.0: Wed Dec 20 21:30:44 PST 2023; root:xnu-10002.81.5~7/RELEASE_ARM64_T6000 arm64
SHELL:
zsh 5.9 (x86_64-apple-darwin23.0)
BASH VERSION:
5.2.21(1)-release
ASDF VERSION:
v0.14.0-ccdd47d
ASDF INTERNAL VARIABLES:
ASDF_DEFAULT_TOOL_VERSIONS_FILENAME=.tool-versions
ASDF_DATA_DIR=/Users/sebastianblask/.asdf
ASDF_DIR=/Users/sebastianblask/.asdf
ASDF_CONFIG_FILE=/Users/sebastianblask/.asdfrc
ASDF INSTALLED PLUGINS:
direnv https://github.com/asdf-community/asdf-direnv.git master 2b649c8
editorconfig-checker https://github.com/gabitchov/asdf-editorconfig-checker.git master 9326459
github-cli https://github.com/bartlomiejdanek/asdf-github-cli.git master e0605b7
iamlive https://github.com/chessmango/asdf-iamlive.git main a986640
nodejs https://github.com/asdf-vm/asdf-nodejs.git master 9c4e0f2
pre-commit https://github.com/jonathanmorley/asdf-pre-commit.git master 26bfc42
python https://github.com/danhper/asdf-python.git master 5e277e2
ruby https://github.com/asdf-vm/asdf-ruby.git master 3035a4a
rust https://github.com/asdf-community/asdf-rust.git master 8436012
shfmt https://github.com/luizm/asdf-shfmt.git master a42c5ff
steampipe https://github.com/carnei-ro/asdf-steampipe.git main 261baed
terraform-docs https://github.com/looztra/asdf-terraform-docs.git master acfd01c
terraform https://github.com/asdf-community/asdf-hashicorp.git master 197e3ec
tflint https://github.com/skyzyx/asdf-tflint.git master 37e7eb9
tfsec https://github.com/woneill/asdf-tfsec.git main c36fac5
trivy https://github.com/zufardhiyaulhaq/asdf-trivy.git master 537a22a
asdf plugins affected (if relevant)
nodejs - had the same problem with eslint_d for example, so it's not a problem of typescript-language-server. I could not reproduce the problem with Python and pre-commit
I have the same issue with yarn
.
$ asdf --version
v0.14.0
$
$ asdf list nodejs
16.18.0
16.20.2
18.15.0
18.16.0
18.17.1
18.18.0
18.18.2
18.19.1
20.10.0
*20.11.1
$ node --version
v20.11.1
$
$ cat .tool-versions
nodejs 20.11.1
$
$ npm list -g | grep yarn
└── yarn@1.22.22
$
$ yarn --version
No preset version installed for command yarn
Please install a version by running one of the following:
asdf install nodejs 20.11.1
or add one of the following versions in your config file at /Users/v_pgoncalves/Development/GoDaddy/cx-spa/.tool-versions
nodejs 18.16.0
I'm having this problem as well
nodejs 18.19.1 20.11.0
What exactly is this line doing?
I suspect that it's making the old version available, the one that you don't want, to what you're trying to run.
My goal is to update from nodejs 16.15.0 to 18.0.0. Installing 18 and then telling asdf to use it with a .tool-versions does not work, even after doing asdf reshim nodejs 18.0.0
asdf
shims support multiple versions. But for each version (of nodejs, in this case), the module needs to be installed separately. To see why, run the command:
asdf which tsserver
/Users/sebastianblask/.asdf/installs/nodejs/20.11.0/bin/tsserver
which isn't visible to nodejs 18.19.1.
This is expected behaviour. Anything you install with one version of a tool should not be found for another version. As suggested, you can list multiple versions so there is a form of fallback if a shim is found in a later listed version, but this defeats the purpose a bit, as mentioned.
asdf global support was not designed how one would expect. It is not always present. It works like any other .tool-versions
file. How it works is, asdf walks up the directory tree, reading any .tool-versions
it finds in each directory, up to the root directory /
. It compiles a list of tools across multiple .tool-versions
files for every plugin installed, where the "selected" version is the first found (closest to current working directory). asdf current
will show you the result of this. Run it in your project and it will show you nodejs 18.19.1
which does not have tsserver
installed. That's expected. Run asdf current
in $HOME
and you will see nodejs 20.11.0
from $HOME/.toolversions
.
"global" is just $HOME/.tool-versions
. So usually found last while walking up the directory tree. And if you are outside of $HOME, then "global" set values wouldn't be found as $HOME/.tool-versions
would never be read.
asdf was not designed for system dependencies while also managing the project-specific dependencies. "global" was added early on as a catch all, not to imply usage anywhere.