[lsp-volar] Typescript is not detected correctly
Thank you for the bug report
- [X] I am using the latest version of
lsp-moderelated 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
- Install volar per instructions
- Open any
.vuefile
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
You may fix this out if you do M-: (lsp-package-ensure 'typescript nil nil) RET
@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.
would something like this work?
(lsp-register-custom-settings '(("typescript.tsdk" "/opt/homebrew/lib/node_modules/typescript" t)
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
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. 🤔
I also got bothered by the same problem and spent a couple of hours locating the problem.
Firstly, the
typescriptdependency is defined as follows:(lsp-dependency 'typescript '(:system "tsserver") '(:npm :package "typescript" :path "tsserver"))This means that it first attempts to find the
tsserverbinary in thesystem. If it exists, the path to it is returned.If it doesn't exist, it then returns the
tsserverinstalled inlsp-server-install-dir.In Doom Emacs or OP @Daut's configuration,
node_modules/.binis added to$PATH. This causes(lsp-package-path 'typescript)to hit the:systemcondition (as the fileproject/node_modules/.bin/tsserverexists).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")returnstsserverinstead of the absolute path. cc @yyoncho
Thanks @sdvcrx! That solved it for me.