emacs-lsp / lsp-mode

Emacs client/library for the Language Server Protocol
https://emacs-lsp.github.io/lsp-mode
GNU General Public License v3.0
4.81k stars 890 forks source link

[lsp-volar] Typescript is not detected correctly #4313

Open daut opened 10 months ago

daut commented 10 months ago

Thank you for the bug report

Bug description

Getting the following error even though typescript is installed globally

LSP :: [lsp-volar] Typescript is not detected correctly. Please ensure the npm package typescript is installed in your project or system (npm install -g typescript), otherwise open an issue

I'm using brew on Mac OS to install packages. This is the path to global installation of typescript

npm list --global --parseable typescript
/opt/homebrew/lib/node_modules/typescript

Steps to reproduce

  1. Install volar per instructions
  2. Open any .vue file

Expected behavior

lsp-volar should detect typescript installed globally.

Which Language Server did you use?

lsp-volar

OS

MacOS

Error callstack

No response

Anything else?

No response

yyoncho commented 10 months ago

You may fix this out if you do M-: (lsp-package-ensure 'typescript nil nil) RET

daut commented 10 months ago

@yyoncho thanks for trying to help!

Unfortunately this didn't resolve the issue. I can see typescript present inside ~/.emacs.d/var/lsp/server/npm but still seeing the same error.

As a temporary workaround I was able to place typescript folder inside project's node_modules folder, but would like to find a way to resolve the issue without having to install typescript for each project.

jacobzlogar commented 8 months ago

would something like this work?

(lsp-register-custom-settings '(("typescript.tsdk" "/opt/homebrew/lib/node_modules/typescript" t)
sdvcrx commented 7 months ago

I also got bothered by the same problem and spent a couple of hours locating the problem.

Firstly, the typescript dependency is defined as follows:

(lsp-dependency 'typescript
                '(:system "tsserver")
                '(:npm :package "typescript"
                       :path "tsserver"))

This means that it first attempts to find the tsserver binary in the system. If it exists, the path to it is returned.

If it doesn't exist, it then returns the tsserver installed in lsp-server-install-dir.

In Doom Emacs or OP @Daut's configuration, node_modules/.bin is added to $PATH. This causes (lsp-package-path 'typescript) to hit the :system condition (as the file project/node_modules/.bin/tsserver exists).


So, the workaround is as follows:

(after! lsp-volar
  ;; remove :system after lsp-volar loaded
  (lsp-dependency 'typescript
                  '(:npm :package "typescript"
                    :path "tsserver")))

I've also noticed another issue: the behavior of lsp--system-path doesn't align with its documentation,

Otherwise, return the absolute path to the executable defined by PATH or nil

However, in reality, (lsp--system-path "tsserver") returns tsserver instead of the absolute path. cc @yyoncho

jcs090218 commented 7 months ago

I also encountered some issues with the typescript-language server. I've tried M-x lsp-describe-session, and everything shown to be working, but I couldn't get the completion to work. 🤔

daut commented 7 months ago

I also got bothered by the same problem and spent a couple of hours locating the problem.

Firstly, the typescript dependency is defined as follows:

(lsp-dependency 'typescript
                '(:system "tsserver")
                '(:npm :package "typescript"
                       :path "tsserver"))

This means that it first attempts to find the tsserver binary in the system. If it exists, the path to it is returned.

If it doesn't exist, it then returns the tsserver installed in lsp-server-install-dir.

In Doom Emacs or OP @Daut's configuration, node_modules/.bin is added to $PATH. This causes (lsp-package-path 'typescript) to hit the :system condition (as the file project/node_modules/.bin/tsserver exists).

So, the workaround is as follows:

(after! lsp-volar
  ;; remove :system after lsp-volar loaded
  (lsp-dependency 'typescript
                  '(:npm :package "typescript"
                    :path "tsserver")))

I've also noticed another issue: the behavior of lsp--system-path doesn't align with its documentation,

Otherwise, return the absolute path to the executable defined by PATH or nil

However, in reality, (lsp--system-path "tsserver") returns tsserver instead of the absolute path. cc @yyoncho

Thanks @sdvcrx! That solved it for me.

UncleBela commented 2 months ago

This is solved by installing typescript-language-server via npm.: npm install -g typescript-language-server.