Error executing lua vim/_init_packages.lua:0: module 'vim.lsp' not found

Hello everyone,

First off, apologies if this isn’t the right place, please point in in the right direction if that is the case. Basically, I upgraded Neovim to version 0.7 in order to be able to use Github Copilot. I may have tried in the past to set up an LSP for Nvim, which may be causing my bug.

Ever since my upgrade, whenever I start up Nvim, I get the following error message (same one as the title):
Error executing lua vim/_init_packages.lua:0: module 'vim.lsp' not found, followed by

        no field package.preload['vim.lsp']
        no file './vim/lsp.lua'
        no file '/home/runner/work/neovim/neovim/.deps/usr/share/luajit-2.1.0-beta3/vim/lsp.lua'
        no file '/usr/local/share/lua/5.1/vim/lsp.lua'
        no file '/usr/local/share/lua/5.1/vim/lsp/init.lua'
        no file '/home/runner/work/neovim/neovim/.deps/usr/share/lua/5.1/vim/lsp.lua'
        no file '/home/runner/work/neovim/neovim/.deps/usr/share/lua/5.1/vim/lsp/init.lua'
        no file './vim/lsp.so'
        no file '/usr/local/lib/lua/5.1/vim/lsp.so'
        no file '/home/runner/work/neovim/neovim/.deps/usr/lib/lua/5.1/vim/lsp.so'
        no file '/usr/local/lib/lua/5.1/loadall.so'
        no file './vim.so'
        no file '/usr/local/lib/lua/5.1/vim.so'
        no file '/home/runner/work/neovim/neovim/.deps/usr/lib/lua/5.1/vim.so'
        no file '/usr/local/lib/lua/5.1/loadall.so'
stack traceback:
        [C]: in function 'require'
        vim/_init_packages.lua: in function '__index'
        [string "luaeval()"]:1: in main chunk

How can I fix this? Is there a way I can tell Nvim to forget about the LSP? I tried looking in ~/.config/nvim/init.vim, but it’s just basic stuff:

set runtimepath^=~/.vim runtimepath+=~/.vim/after
let &packpath = &runtimepath
source ~/.vimrc
set tabstop=4
set softtabstop=4
set expandtab
set nu
set list
set clipboard=unnamedplus
set noshowmatch
set nohlsearch

No mention of Lua packages. Where can I find this _init_packages.lua file? I haven’t been able to find it using the find utility.

How did you build/install neovim? This sounds like some issue with your installation. neovim should look for vim.lsp in your runtime path using a custom Lua package loader. What’s your runtimepath? Can you repro it with nvim --clean? You can try something like:

nvim --clean --headless -E +'lua print(vim.inspect(vim.lsp.get_active_clients()))' +q

It should print “{}”.

Hello, thank you very much for you response. :slight_smile:

When I echo $runtimepath I get nothing, although maybe this is not how to find runtimepath?

When I type in the command you suggested -
nvim --clean --headless -E +'lua print(vim.inspect(vim.lsp.get_active_clients()))' +q
I get the same error message -
Error detected while processing command line: E5108: Error executing lua vim/_init_packages.lua:0: module 'vim.lsp' not found: no field package.preload['vim.lsp'] no file './vim/lsp.lua' no file '/home/runner/work/neovim/neovim/.deps/usr/share/luajit-2.1.0-beta3/vim/lsp.lua' no file '/usr/local/share/lua/5.1/vim/lsp.lua' no file '/usr/local/share/lua/5.1/vim/lsp/init.lua' no file '/home/runner/work/neovim/neovim/.deps/usr/share/lua/5.1/vim/lsp.lua' no file '/home/runner/work/neovim/neovim/.deps/usr/share/lua/5.1/vim/lsp/init.lua' no file './vim/lsp.so' no file '/usr/local/lib/lua/5.1/vim/lsp.so' no file '/home/runner/work/neovim/neovim/.deps/usr/lib/lua/5.1/vim/lsp.so' no file '/usr/local/lib/lua/5.1/loadall.so' no file './vim.so' no file '/usr/local/lib/lua/5.1/vim.so' no file '/home/runner/work/neovim/neovim/.deps/usr/lib/lua/5.1/vim.so' no file '/usr/local/lib/lua/5.1/loadall.so' stack traceback: [C]: in function 'require' vim/_init_packages.lua: in function '__index' [string ":lua"]:1: in main chunk⏎

If I recall correctly I think I installed using apt, I am on Ubuntu. I may try uninstalling and re-installing to see if that fixes it, thank you for suggesting the problem is likely with the installation. :slight_smile:

Thank you for your reply.

When I type echo $runtimepath, nothing shows up, in other words the variable is not set.

I uninstalled and re-installed neovim. When I run it from where I downloaded and unziped it (my home folder, ~), it works fine. If I try to move the binary to another folder (eg /usr/local/bin), I have problems.

Does this mean I should move the entire folder /nvim-linux64 to where I move the binary in order to have it be able to find everything?

Thank you again for your reply, and your intution that it was the installation was correct. :slight_smile:

That’s not how you test this. It’s either set rtp? (for the Vim variable holding the full runtime path) or echo $VIMRUNTIME (for the path where the bundled runtime files are installed to).

ah, thanks for letting me know.

The command echo $VIMRUNTIME returns an empty string, however, opening neovim and typing set rtp? returns

runtimepath=~/.vim,~/.vim/pack/*/start/*,~/.config/nvim,~/.config/nvim/pack/*/
start/*,/etc/xdg/xdg-ubuntu/nvim,/etc/xdg/nvim,~/.local/share/nvim/site,/usr/sha
re/ubuntu/nvim/site,~/.local/share/flatpak/exports/share/nvim/site,/var/lib/flat
pak/exports/share/nvim/site,/usr/local/share/nvim/site,/usr/share/nvim/site,/var
/lib/snapd/desktop/nvim/site,~/nvim-linux64/share/nvim/runtime,~/nvim-linux64/sh
are/nvim/runtime/pack/dist/opt/matchit,~/nvim-linux64/lib/nvim,~/.vim/pack/*/sta
rt/*/after,/var/lib/snapd/desktop/nvim/site/after,/usr/share/nvim/site/after,/us
r/local/share/nvim/site/after,/var/lib/flatpak/exports/share/nvim/site/after,~/.
local/share/flatpak/exports/share/nvim/site/after,/usr/share/ubuntu/nvim/site/af
ter,~/.local/share/nvim/site/after,/etc/xdg/nvim/after,/etc/xdg/xdg-ubuntu/nvim/
after,~/.config/nvim/after,~/.vim/after

Did you ever manage to find a solution for this issue? I’m running into the exact same error/stacktrace

Thanks @fsouza for the hint, the only way to resolve this issue was building the nvim on my machine.
to build i follow those instructions:

I think the issue is I updated the binary at location which nvim, but not the runtime files. I fixed it by:

  • git cloning neovim
  • checking out the tagged version that matches the binary nvim -v
  • copied the runtime from the cloned neovim repo to usr/share/nvim/runtime

here’s a bash script:

git clone https://github.com/neovim/neovim.git
cd neovim
git checkout v0.9.5
sudo cp -r runtime /usr/share/nvim/