lsp-mode
lsp-mode copied to clipboard
ts-ls: Wrong lsp-clients-typescript-server-path
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
https://github.com/emacs-lsp/lsp-mode/pull/4202 made some changes to handle a deprecated argument in the language server. This included changing lsp-clients-typescript-server-path()
to return:
https://github.com/emacs-lsp/lsp-mode/blob/01bd566c0508993202b08071ed7037c9fc4e3329/clients/lsp-javascript.el#L803
For me this evaluates to ~/.emacs.d/var/lsp/server/npm/typescript/bin/node_modules/typescript/lib
, while tsserver.js
is actually in ~/.emacs.d/var/lsp/server/npm/typescript/lib/node_modules/typescript/lib
. So I guess the line above should be:
(f-join (f-parent (f-parent (lsp-package-path 'typescript))) "lib" "node_modules" "typescript" "lib"))))
Steps to reproduce
- Open a
.js
file withts-ls
, the following error appears:LSP :: Error from the Language Server: Request initialize failed with message: Could not find a valid TypeScript installation. Please ensure that the "typescript" dependency is installed in the workspace or that a valid
tsserver.pathis specified. Exiting. (Internal Error)
Expected behavior
ts-ls
starts normally
Which Language Server did you use?
lsp-javascript/ts-ls
OS
Linux
Error callstack
No response
Anything else?
No response
I'm having this issue as well. Reverting the change from #4202 to line 803 resolved it.
@kiennq - seems like it is a regression?
I am having a rather hard time getting lsp to work in a TypeScript project in a subdirectory due to this problem. Also, the original PR does not work in environments that do not use node_modules such as yarn PnP, and I expect that some people will have trouble with that.
I'm having this issue as well. Reverting the change from #4202 to line 803 resolved it.
same issue here, and resolved by follow @hamaker's suggestion.
I guess that new code didn't include all kind of npm install path.
For my case, I'm using nvm, and my global install path is in ~/.nvm/
And I can use M-x lsp-install-server
command, and that tsc
& tsserver
bin install inside ~/.emacs.d/.cache/lsp/npm/typescript/bin
didn't really deep into what's going on here, though, hope someone can solve this problem :)
try to dig deeper into the problem, I think that maybe not related to various of npm install path.
Maybe that logic just wrong in linux environment?
I thought that PR with the problem try to fix issue on window's version
I'm getting the same problem in (ubuntu) Linux; also:
Typescript specified through user setting ignored due to invalid path ..completely_wrong_path..
Deleting ~/.emacs.d/.cache/lsp/npm/typescript*
and installing typescript
and typescript-language-server
globally mitigated the problem; the language server isn't being picked up under ~/.emacs.d/.cache/lsp
, although eslint
and other node-based servers are correctly detected.
This, however, does not happen in macOS; all language servers are correctly detected under ~/.emacs.d/.cache/lsp
On my machine, my emacs.d cache folder looks like this:
~/.emacs.d/.cache/lsp/npm/typescript
├── bin
│ ├── tsc -> ../lib/node_modules/typescript/bin/tsc
│ └── tsserver -> ../lib/node_modules/typescript/bin/tsserver
└── lib
└── node_modules
└── typescript
5 directories, 2 files
Similar to the issue description, the elisp statement linked there evaluates to ~/.emacs.d/.cache/lsp/npm/typescript/bin/node_modules/typescript/lib
which doesn't exist.
The fix in https://github.com/emacs-lsp/lsp-mode/pull/4284 works for me, and as a quick workaround without having to locally edit my elpa files, adding a node_modules symlink in the path that lsp-mode is erroneously looking in also works:
$ cd ~/.emacs.d/.cache/lsp/npm/typescript/bin && ln -s ../lib/node_modules
I'm seeing this error on Debian Linux with Emacs 29.2. As a temporary workaround, I've created a symlink via
ln -s <path_prefix>/lsp/npm/typescript/lib/node_modules <path_prefix>/lsp/npm/typescript/bin
NB Amend <path_prefix>
to suit the paths in your local installation and see the lsp-log
error messages for the path where LSP is expecting to find the node_modules
directory.
My problem was solved by the PR I sent out last month, does this solve yours? fix: remove direct references to the node_modules directory by ncaq · Pull Request #4333 · emacs-lsp/lsp-mode
Can someone give this a test? 🤔 Thanks!
Thanks @ncaq - your PR seems to fix the problem for me.
This doesn't look right. If you are on windows, the path looks like: 🤔
~/.emacs.d/.cache/lsp/npm/typescript/node_modules/typescript/lib
Can someone test #4389? It should work on both Unix-like and Windows systems. 🤔
Can someone test #4389? It should work on both Unix-like and Windows systems. 🤔
It looks good to me.
Completed in #4389.
I'm referencing the node_modules directory from the lsp root, so the problem isn't solved in environments with node_modules in subdirectories, etc. that my PR solved. should this be a separate issue?
Perhaps you are under the mistaken impression that my PR is simply to change the PATH specification of the original issue contributor, while my PR is to stop referring to the PATH directly... Well, I'll make sure it works on Windows.
I have checked it works on Windows and found that it certainly does not work on Windows, even with the content of my PR, so I would like to correct it.
@jcs090218 The problem was not completely resolved in my environment, but your point about it not working on Windows was correct, so I have corrected my submitted PR with reference to your correction as well. I would be happy to review it for you. fix: remove direct references to the node_modules directory by ncaq · Pull Request #4333 · emacs-lsp/lsp-mode
I'm referencing the node_modules directory from the lsp root, so the problem isn't solved in environments with node_modules in subdirectories, etc. that my PR solved. should this be a separate issue?
It's better to be in separate issues. 👍 The title is a bit misleading. 🤔