Search code examples
pythonneovimpyright

Pyright LSP Install in neovim - 'node:util' module not found


Fresh installed neovim on a new LinuxMint machine with lsp-config, mason plugins and pyright LSP Server (through Mason) and found out that it was not working with lsp.log registering this !!!

 .../vim/lsp/rpc.lua:734    "rpc"   "/home/manjunath/.local/share/nvim-kick/mason/bin/pyright-langserver"   "stderr"    "internal/modules/cjs/loader.js:818
  throw err;
  ^

Error: Cannot find module 'node:util'
Require stack:
- /home/manjunath/.local/share/nvim-kick/mason/packages/pyright/node_modules/pyright/dist/pyright-langserver.js
- /home/manjunath/.local/share/nvim-kick/mason/packages/pyright/node_modules/pyright/langserver.index.js
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:815:15)
    at Function.Module._load (internal/modules/cjs/loader.js:667:27)
    at Module.require (internal/modules/cjs/loader.js:887:19)
    at require (internal/modules/cjs/helpers.js:74:18)
    at Object.9632 (/home/manjunath/.local/share/nvim-kick/mason/packages/pyright/node_modules/pyright/dist/pyright-langserver.js:1:557)
    at o (/home/manjunath/.local/share/nvim-kick/mason/packages/pyright/node_modules/pyright/dist/pyright-langserver.js:1:1142)
    at Object.1264 (/home/manjunath/.local/share/nvim-kick/mason/packages/pyright/node_modules/pyright/dist/vendor.js:2:794958)
    at o (/home/manjunath/.local/share/nvim-kick/mason/packages/pyright/node_modules/pyright/dist/pyright-langserver.js:1:1142)
    at Object.1476 (/home/manjunath/.local/share/nvim-kick/mason/packages/pyright/node_modules/pyright/dist/pyright-internal.js:1:441151)
    at o (/home/manjunath/.local/share/nvim-kick/mason/packages/pyright/node_modules/pyright/dist/pyright-langserver.js:1:1142) {
  code: 'MODULE_NOT_FOUND',
  requireStack: [
    '/home/manjunath/.local/share/nvim-kick/mason/packages/pyright/node_modules/pyright/dist/pyright-langserver.js',
    '/home/manjunath/.local/share/nvim-kick/mason/packages/pyright/node_modules/pyright/langserver.index.js'
  ]
}

Actions taken:

  • Fresh installed node and npm again.
  • Checked with a sample node app using utils module - WORKING

Outcome:

  • Working pyright LSP server with Neovim

Solution

  • Found out what the issue was.

    node.js on apt was outdated. Installing latest version from here fixed it.