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

Shim not using global NodeJS version #822

Closed
delucca opened this issue Oct 26, 2020 · 15 comments
Closed

Shim not using global NodeJS version #822

delucca opened this issue Oct 26, 2020 · 15 comments
Labels

Comments

@delucca
Copy link

delucca commented Oct 26, 2020

Hi!

I'm trying to initialize my lsp-mode (at Emacs) using the ts-ls tsserver to do so. But, when I start the server the following error happens:

Command "/home/odelucca/.asdf/shims/typescript-language-server --tsserver-path /home/odelucca/.asdf/shims/tsserver --stdio" is present on the path.
Command "/home/odelucca/.asdf/shims/typescript-language-server --tsserver-path /home/odelucca/.asdf/shims/tsserver --stdio" is present on the path.
Found the following clients for /home/odelucca/Code/odelucca/execution-mode@budproj/src/server/index.ts: (server-id ts-ls, priority -2)
The following clients were selected based on priority: (server-id ts-ls, priority -2)
[tsserver] asdf: No preset version installed for command tsserver
Please install the missing version by running one of the following:

asdf install nodejs 15.0.0

or add one of the following in your .tool-versions file:


[tsserver] nodejs 12.18.1

Cancelling textDocument/codeAction(5) in hook post-command-hook

It is strange, because I have NodeJS version 12.18.1 installed, as you can se:

execution-mode@budproj on  feature/initial-setup [?] via ⬢ v15.0.0 took 3s
❯ asdf list nodejs
  10.15.0
  10.17.0
  12.16.0
  12.16.1
  12.18.1
  12.18.2
  12.18.3
  13.10.1
  13.9.0
  14.0.0
  14.2.0
  15.0.0

And also, the project is not using NodeJS 12.18.1, it is using 15.0.0:

# .tool-versions
nodejs 15.0.0

If I change the .tool-versions file to use Node 12.18.1 it works, but I should not do so, since my project required 15.0.0

Any idea how to fix it?

@maxie7
Copy link

maxie7 commented Nov 2, 2020

I have the same problem too!!! With asdf current I have nodejs 14.15.0 ... I intsalled it globally and also I use it locally for my project (.tool-versions has nodejs 14.15.0). But if I do node -v from my terminal it shows me v.12.15.0
My OS Ubuntu 20.04.1 LTS

@maxie7
Copy link

maxie7 commented Nov 2, 2020

I've upgraded node plugin of asdf, but it didn't resolve the problem

@maxie7
Copy link

maxie7 commented Nov 2, 2020

I've solved the problem by adding
. $HOME/.asdf/asdf.sh
to my .zshrc file. I didn't do it earlier because in docs they say

OR use a ZSH Framework plugin like asdf for oh-my-zsh which will source this script and setup completions.

And I use this plugin, because I use oh-my-zsh. So, I think that the bug is inside oh-my-zsh plugin. @delucca , just add what I mentioned and reopen your terminal. This BTW works in Linux

@jthegedus
Copy link
Contributor

@delucca can you show us your asdf info?

@maxie7 My .zshrc looks like this:

fpath=($HOME/.asdf/completions $fpath)
plugins=(
	asdf
)

And I cannot reproduce this issue, so I do not think it's the OMYZSH plugin.

@maxie7
Copy link

maxie7 commented Dec 7, 2020

my .zshrc:

...
plugins=(
    asdf 
    bundler
    bower
    catimg 
    colored-man-pages 
    command-not-found 
    composer 
    docker 
    dotenv
    fasd 
    git
    git-flow
    github
    gem 
    gpg-agent 
    httpie
    heroku 
    jira 
    rvm 
    rake 
    ruby 
    rails 
    repo 
    # ssh-agent 
    sublime 
    symfony2 
    systemd 
    sudo 
    sprunge 
    urltools 
    ubuntu 
    npm 
    web-search  
    zsh-autosuggestions  
)
...
. $HOME/.asdf/asdf.sh

. $HOME/.asdf/completions/asdf.bash

@maxie7
Copy link

maxie7 commented Dec 7, 2020

without
. $HOME/.asdf/asdf.sh
at the end of my .zshrc it doesn't work
I've tested it in two laptops: 1) Debian GNU/Linux 10 (buster) and 2) Ubuntu 20.04.1 LTS

@jthegedus jthegedus added the bug label Dec 9, 2020
@krisalyssa
Copy link

I don't know if this is related, but I was having a similar problem with trying to run yarn:

% yarn -v
asdf: No preset version installed for command yarn
Please install the missing version by running one of the following:

asdf install nodejs 13.8.0

or add one of the following in your .tool-versions file:

nodejs 12.13.0

I eventually (after longer than I'm willing to admit 😄) realized that because I had just installed nodejs 13.8.0, yarn wasn't installed. Instead of erroring out with "command not found", the shim returns a well-intentioned-but-not-quite-helpful message.

@jthegedus
Copy link
Contributor

jthegedus commented Dec 18, 2020

I believe @CraigCottingham has found the cause of the issue, I will use the details he provided for a scenario. I may be off with some of this, but it's the gist as I understand it today.

asdf plugins add shims to the ~/.asdf/shims dir for each binary that the plugin you install manages. That is, asdf plugin add nodejs will add shims for npm, npx, node and perhaps some others. When you install a global binary such as vercel or yarn via a particular node version, it will create the shim for that binary in ~/.asdf/shims. This shim is not associated with a version, but is just an indicator that asdf is managing that binary. When the binary is executed, asdf will lookup the shim, find it's associated plugin, search for a .tool-versions file (or legacy version file if specified) to determine which version of node the user wants, attempts to find the the specific binary under the provided version of node (in say that versions global node_modules). If the binary does not exist, it cannot be executed and thus asdf says

asdf: No preset version installed for command yarn
Please install the missing version by running one of the following:
asdf install nodejs 13.8.0
or add one of the following in your .tool-versions file:
nodejs 12.13.0

This error is somewhat unhelpful. It should probably read something like:

asdf: No installed command <yarn> found for version <nodejs 13.8.0>
      Command <yarn> was found for version <nodejs 12.13.0>

      Either install <yarn> for version <nodejs 13.8.0>
      or
      revert to version <nodejs 12.13.0> with `asdf local nodejs 13.8.0`

To resolve this issue, I think we need to update the error messaging for this scenario.

@delucca does this description help you resolve your issue?

@delucca
Copy link
Author

delucca commented Dec 18, 2020

@jthegedus I think it does.

I'm no longer facing this issue since I've moved from Emacs to Atom, but I think that the error message would make it easier to understand.

But, there is a more complex issue here. I was using a plugin called asdf-yarn, and I think most Yarn users do too. Why does asdf is searching for yarn inside asdf-node instead of asdf-yarn?

@jthegedus
Copy link
Contributor

jthegedus commented Dec 19, 2020

@delucca Sorry, I used the details from @CraigCottingham in this thread. tsserver seemed to be the binary you were facing issues with, his example was yarn installed as a global via npm i -g yarn with the nodejs plugin.

But, there is a more complex issue here. I was using a plugin called asdf-yarn, and I think most Yarn users do too. Why does asdf is searching for yarn inside asdf-node instead of asdf-yarn?

Had yarn been installed via the asdf-yarn plugin then asdf would have errored with

asdf: No preset version installed for command yarn
Please install the missing version by running one of the following:
asdf install yarn 1.22.10
or add one of the following in your .tool-versions file:
yarn 1.20.0

Simplifying my earlier explanation:

asdf > plugins > install tools > shim stored in a global lookup (version independent) @ ~/.asdf/shims.

when a command is executed:

  1. asdf lookup in shim dir ~/.asdf/shims
  2. asdf lookup for plugin that installed shim (can be any plugin, for yarn it could be either asdf-yarn or asdf-nodejs plugin, but asdf knows)
  3. asdf looks up the version specified for the plugin in .tool-versions
  4. asdf attempts to exec binary for that version if it exists.

There is a situation whereby a shim is created for the same tool from different plugins (see #828). Let's take yarn for instance. It can be installed via:

  • asdf-yarn with asdf install yarn <version>
  • asdf-nodejs with npm i -g yarn

on my machine with both asdf-nodejs and asdf-yarn with an installed version of yarn:

# List the plugins and versions that provide a command
➜ asdf shim-versions yarn
nodejs 14.15.2
yarn 1.22.10


# with no version for either nodejs or yarn plugins in .tool-versions
# or versions are set, but those versions didn't have the binary installed for them
➜ asdf which yarn
No preset version installed for command yarn
Please install a version by running one of the following:

asdf install nodejs 14.8.0

or add one of the following versions in your config file at /home/jthegedus/.tool-versions
nodejs 14.15.2
yarn 1.22.10


# with nodejs version set in .tool-versions
➜ asdf which yarn
/home/jthegedus/.asdf/installs/nodejs/14.15.2/.npm/bin/yarn

# with yarn version set in .tool-versions
➜ asdf which yarn
/home/jthegedus/.asdf/installs/yarn/1.22.10/bin/yarn

# with both nodejs & yarn versions set in .tool-versions
➜ asdf which yarn
/home/jthegedus/.asdf/installs/nodejs/14.15.2/.npm/bin/yarn
# this is where my knowledge is lacking as I am unfamiliar with why nodejs is preferred over yarn here as swapping the position in the .tool-versions file doesn't affect resolution, so I think it is dependent on the order returned from `asdf shim-versions yarn`

It is up to the user to manage whether a shim is managed by two different plugins. We provide the tools to investigate this with asdf which <tool> and asdf shim-versions so they know which installation is executed.

We need to improve our error outputs however to make the situation that started this thread more clear.

@nielsbom
Copy link

I went looking for the specific code that gave the error:

printf "%s %s\\n" "No preset version installed for command" "$shim_name"

Unfortunately my bash skills are severely lacking so I can't really update the error message and/or the code that tests it.

@nielsbom
Copy link

But, there is a more complex issue here. I was using a plugin called asdf-yarn, and I think most Yarn users do too. Why does asdf is searching for yarn inside asdf-node instead of asdf-yarn?

Maybe it's good to make a separate issue for that, because this issue started out with something different and the fix for the original issue is (imho) improving the error message per the suggestion of @jthegedus

@misraelson
Copy link

misraelson commented Aug 31, 2021

@jthegedus Improving the error messaging to something similar to what you suggested would be extremely helpful. It is confusing to get a message telling you to install the missing version when you know you have a plugin installed and a version specified in the .tool-versions file.

There are some counter intuitive things with asdf that should be taken care of.

For example when installing postgres with asdf it doesn't add the same flags that homebrew does, such as installing with OpenSSL and other libs. So you end up having to go through documentation to figure out how to add these flags. When installing postgres with homebrew that was taken care of so it ought to be the same seamless process here.

EricCrosson added a commit to EricCrosson/dotfiles that referenced this issue Sep 24, 2021
This addition is necessary to add the `tsserver` command (external to
the one managed by lsp-mode in emacs) with each version of node
installed.

Without this change, I was seeing [this
error](asdf-vm/asdf#822 (comment)).
The root cause is outlined in the next comment.
@maslenkov
Copy link

As for me, the problem was with PATH. I had such .zshrc config

. $(brew --prefix asdf)/asdf.sh

...
export PATH="/usr/local/opt/node@10/bin:$PATH"
...

I don't remember why I added that 😅 .
Of course, if I remove exporting of node@10 or change order then it works.
So check your config twice 😉 .

@Stratus3D
Copy link
Member

Closing this issue because I think #928 is the only remaining bug here for asdf-core.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

8 participants