lsp-mode icon indicating copy to clipboard operation
lsp-mode copied to clipboard

[lsp-volar] Typescript is not detected correctly

Open daut opened this issue 2 years ago • 7 comments

Thank you for the bug report

  • [X] I am using the latest version of lsp-mode related packages.
  • [X] I checked FAQ and Troubleshooting sections
  • [ ] You may also try reproduce the issue using clean environment using the following command: M-x lsp-start-plain

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

daut avatar Jan 26 '24 10:01 daut

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

yyoncho avatar Jan 26 '24 11:01 yyoncho

@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.

daut avatar Jan 26 '24 12:01 daut

would something like this work?

(lsp-register-custom-settings '(("typescript.tsdk" "/opt/homebrew/lib/node_modules/typescript" t)

jacobzlogar avatar Mar 14 '24 18:03 jacobzlogar

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

sdvcrx avatar Apr 12 '24 10:04 sdvcrx

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. 🤔

jcs090218 avatar Apr 13 '24 23:04 jcs090218

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.

daut avatar Apr 16 '24 15:04 daut