1

I'm a beginner nvim user (version v0.11.0-dev). I've got my config forked from kickstart.nvim and it works on my personal machine with EndeavourOS. On my work laptop, I've got Windows with WSL, on which I've installed nvim with the same config. I cannot get typescript LSP to work though. :LspLog says this (the same is thrown when I try to run typescript-language-server manually from ~/.local/share/nvim/mason/bin:

[ERROR][2024-11-19 15:33:21] .../vim/lsp/rpc.lua:759    "rpc"   "/home/<redacted>/.local/share/nvim/mason/bin/typescript-language-server"   "stderr"    "internal/modules/cjs/loader.js:818
  throw err;
  ^
Error: Cannot find module '/home/<redacted>/.local/share/nvim/mason/typescript-language-server/lib/cli.mjs'
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:815:15)
    at Function.Module._load (internal/modules/cjs/loader.js:667:27)
    at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:60:12)
    at internal/main/run_main_module.js:17:47 {
  code: 'MODULE_NOT_FOUND',
  requireStack: []
}

Looks like it searches a non-existent directory, because

ls -la ~/.local/share/nvim/mason/
total 28
drwxr-xr-x 7 <redacted> <redacted> 4096 Nov 18 15:18 .
drwx------ 6 <redacted> <redacted> 4096 Nov 19 11:10 ..
drwxr-xr-x 2 <redacted> <redacted> 4096 Nov 19 11:07 bin
drwxr-xr-x 5 <redacted> <redacted> 4096 Nov 19 11:07 packages
drwxr-xr-x 3 <redacted> <redacted> 4096 Nov 18 15:18 registries
drwxr-xr-x 3 <redacted> <redacted> 4096 Nov 18 15:18 share
drwxr-xr-x 2 <redacted> <redacted> 4096 Nov 19 11:07 staging

and typescript-language-server exists in packages and bin. I'm not sure what went wrong here.

:checkhealth mason does not indicate any errors (apart from warnings about language executables that I don't have)

1
  • Can you verify that your node.js and npm is correctly installed? Especially if with :checkhealth mason you see any warnings regarding node.js installation Commented Nov 20, 2024 at 11:50

1 Answer 1

1

I managed to fix this by editing the typescript-language-server script in ~/.local/share/nvim/mason/bin. It's looking in the wrong directory for some reason.

Instead of

if [ -x "$basedir/node" ]; then
  exec "$basedir/node"  "$basedir/../typescript-language-server/lib/cli.mjs" "$@"
else 
  exec node  "$basedir/../typescript-language-server/lib/cli.mjs" "$@"
fi

change it to

if [ -x "$basedir/node" ]; then
  exec "$basedir/node"  "$basedir/../packages/typescript-language-server/node_modules/typescript-language-server/lib/cli.mjs" "$@"
else 
  exec node  "$basedir/../packages/typescript-language-server/node_modules/typescript-language-server/lib/cli.mjs" "$@"
fi

and it works for me.

EDIT: The root cause of this issue seems to have been not having npm installed through WSL. WSL was using the windows npm installation instead of its own. I installed npm into WSL through nvm and reinstalled the TS LS and everything worked fine first try.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.