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

ts-ls: Wrong lsp-clients-typescript-server-path

Open eginhard opened this issue 8 months ago • 5 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

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

  1. Open a .js file with ts-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.path is 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

eginhard avatar Dec 09 '23 19:12 eginhard

I'm having this issue as well. Reverting the change from #4202 to line 803 resolved it.

hamaker avatar Dec 19 '23 11:12 hamaker

@kiennq - seems like it is a regression?

yyoncho avatar Dec 19 '23 15:12 yyoncho

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.

ncaq avatar Jan 23 '24 15:01 ncaq

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 :)

idhowardgj94 avatar Feb 05 '24 13:02 idhowardgj94

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

idhowardgj94 avatar Feb 05 '24 13:02 idhowardgj94

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

stradicat avatar Mar 05 '24 19:03 stradicat

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

hyperair avatar Mar 06 '24 05:03 hyperair

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.

ghferrari avatar Mar 12 '24 12:03 ghferrari

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

ncaq avatar Mar 14 '24 22:03 ncaq

Can someone give this a test? 🤔 Thanks!

jcs090218 avatar Mar 16 '24 07:03 jcs090218

Thanks @ncaq - your PR seems to fix the problem for me.

ghferrari avatar Mar 20 '24 09:03 ghferrari

This doesn't look right. If you are on windows, the path looks like: 🤔

~/.emacs.d/.cache/lsp/npm/typescript/node_modules/typescript/lib

jcs090218 avatar Mar 23 '24 03:03 jcs090218

Can someone test #4389? It should work on both Unix-like and Windows systems. 🤔

jcs090218 avatar Mar 24 '24 00:03 jcs090218

Can someone test #4389? It should work on both Unix-like and Windows systems. 🤔

It looks good to me.

kiennq avatar Mar 24 '24 11:03 kiennq

Completed in #4389.

jcs090218 avatar Mar 24 '24 18:03 jcs090218

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?

ncaq avatar Mar 27 '24 08:03 ncaq

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.

ncaq avatar Mar 27 '24 09:03 ncaq

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.

ncaq avatar Mar 27 '24 09:03 ncaq

@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

ncaq avatar Mar 27 '24 13:03 ncaq

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

jcs090218 avatar Mar 27 '24 22:03 jcs090218