folke / lazy.nvim

šŸ’¤ A modern plugin manager for Neovim
https://lazy.folke.io/
Apache License 2.0
14.93k stars 361 forks source link

bug: Setup function can't find references to other lazy modules #1205

Closed sanevillain closed 11 months ago

sanevillain commented 11 months ago

Did you check docs and existing issues?

Neovim version (nvim -v)

NVIM v0.10.0-dev-64b53b7

Operating system/version

MacOS Venture 13.6

Describe the bug

Installing the plugin with the steps described in the read me

local lazypath = vim.fn.stdpath("data") .. "/lazy/lazy.nvim"
if not vim.loop.fs_stat(lazypath) then
  vim.fn.system({
    "git",
    "clone",
    "--filter=blob:none",
    "https://github.com/folke/lazy.nvim.git",
    "--branch=stable", -- latest stable release
    lazypath,
  })
end
vim.opt.rtp:prepend(lazypath)

require("lazy").setup()

is failing with the following messages

Error detected while processing /Users/denismail/dotfiles/nvim/init.lua:
E5113: Error while calling lua chunk: ...smail/.local/share/nvim/lazy/lazy.nvim/lua/lazy/init.lua:75: module 'lazy.stats' not found:
        no field package.preload['lazy.stats']module '^[LJ^B^HE@/Users/denismail/.local/share/nvim/lazy/lazy.nvim/lua/lazy/stats.lua<ba>^A' not found:
        no field package.preload['^[LJ^B^HE@/Users/denismail/.local/share/nvim/lazy/lazy.nvim/lua/lazy/stats.lua<ba>^A']
cache_loader: module ^[LJ^B^HE@/Users/denismail/.local/share/nvim/lazy/lazy.nvim/lua/lazy/stats.lua<ba>^A not found
cache_loader_lib: module ^[LJ^B^HE@/Users/denismail/.local/share/nvim/lazy/lazy.nvim/lua/lazy/stats.lua<ba>^A not found
        no file './^[LJ^B^HE@/Users/denismail//local/share/nvim/lazy/lazy/nvim/lua/lazy/stats/lua<ba>^A.lua'
        no file '/Users/runner/work/neovim/neovim/.deps/usr/share/luajit-2.1/^[LJ^B^HE@/Users/denismail//local/share/nvim/lazy/lazy/nvim/lua/lazy/stats/lua<ba>^A.lua'
        no file '/usr/local/share/lua/5.1/^[LJ^B^HE@/Users/denismail//local/share/nvim/lazy/lazy/nvim/lua/lazy/stats/lua<ba>^A.lua'
        no file '/usr/local/share/lua/5.1/^[LJ^B^HE@/Users/denismail//local/share/nvim/lazy/lazy/nvim/lua/lazy/stats/lua<ba>^A/init.lua'
        no file '/Users/runner/work/neovim/neovim/.deps/usr/share/lua/5.1/^[LJ^B^HE@/Users/denismail//local/share/nvim/lazy/lazy/nvim/lua/lazy/stats/lua<ba>^A.lua'
        no file '/Users/runner/work/neovim/neovim/.deps/usr/share/lua/5.1/^[LJ^B^HE@/Users/denismail//local/share/nvim/lazy/lazy/nvim/lua/lazy/stats/lua<ba>^A/init.lua'
        no file './^[LJ^B^HE@/Users/denismail//local/share/nvim/lazy/lazy/nvim/lua/lazy/stats/lua<ba>^A.so'
        no file '/usr/local/lib/lua/5.1/^[LJ^B^HE@/Users/denismail//local/share/nvim/lazy/lazy/nvim/lua/lazy/stats/lua<ba>^A.so'
        no file '/Users/runner/work/neovim/neovim/.deps/usr/lib/lua/5.1/^[LJ^B^HE@/Users/denismail//local/share/nvim/lazy/lazy/nvim/lua/lazy/stats/lua<ba>^A.so'
        no file '/usr/local/lib/lua/5.1/loadall.so'
        no file './^[LJ^B^HE@/Users/denismail/.so'
        no file '/usr/local/lib/lua/5.1/^[LJ^B^HE@/Users/denismail/.so'
        no file '/Users/runner/work/neovim/neovim/.deps/usr/lib/lua/5.1/^[LJ^B^HE@/Users/denismail/.so'
        no file '/usr/local/lib/lua/5.1/loadall.so'
cache_loader_lib: module lazy.stats not found
        no file './lazy/stats.lua'
        no file '/Users/runner/work/neovim/neovim/.deps/usr/share/luajit-2.1/lazy/stats.lua'
        no file '/usr/local/share/lua/5.1/lazy/stats.lua'
        no file '/usr/local/share/lua/5.1/lazy/stats/init.lua'
        no file '/Users/runner/work/neovim/neovim/.deps/usr/share/lua/5.1/lazy/stats.lua'
        no file '/Users/runner/work/neovim/neovim/.deps/usr/share/lua/5.1/lazy/stats/init.lua'
        no file './lazy/stats.so'
        no file '/usr/local/lib/lua/5.1/lazy/stats.so'
        no file '/Users/runner/work/neovim/neovim/.deps/usr/lib/lua/5.1/lazy/stats.so'
        no file '/usr/local/lib/lua/5.1/loadall.so'
        no file './lazy.so'
        no file '/usr/local/lib/lua/5.1/lazy.so'
        no file '/Users/runner/work/neovim/neovim/.deps/usr/lib/lua/5.1/lazy.so'
        no file '/usr/local/lib/lua/5.1/loadall.so'
stack traceback:
        [C]: in function 'require'
        ...smail/.local/share/nvim/lazy/lazy.nvim/lua/lazy/init.lua:75: in function 'setup'
        /Users/denismail/dotfiles/nvim/init.lua:28: in main chunk

This has been tested with the latest nightly version of neovim, along with the latest stable version and the outcome was always the same.

I want to note that I also use lunarvim and thought that somehow the runtime of lunarvim was interfering here, but it shouldn't be the case as all of the lazy plugins are stored in a completely separate location.

Steps To Reproduce

  1. Have a fresh neovim instance
  2. Add the installation instructions from the README

Expected Behavior

I expect the setup function to be able to load other lazy modules that it relies on and doesn't crash

Repro

-- DO NOT change the paths and don't remove the colorscheme
local root = vim.fn.fnamemodify("./.repro", ":p")

-- set stdpaths to use .repro
for _, name in ipairs({ "config", "data", "state", "cache" }) do
  vim.env[("XDG_%s_HOME"):format(name:upper())] = root .. "/" .. name
end

local lazypath = vim.fn.stdpath("data") .. "/lazy/lazy.nvim"
if not vim.loop.fs_stat(lazypath) then
  vim.fn.system({
    "git",
    "clone",
    "--filter=blob:none",
    "https://github.com/folke/lazy.nvim.git",
    "--branch=stable", -- latest stable release
    lazypath,
  })
end
vim.opt.rtp:prepend(lazypath)

require("lazy").setup()
max397574 commented 11 months ago

could you provide a minimal repro? because the minimal repro uses the exact same code snippet and people don't get issues there so I think it's a problem with your setup

abeldekat commented 11 months ago

..smail/.local/share/nvim/lazy/lazy.nvim/lua/lazy/init.lua:75:

Lazy's init.lua is found. Could you check if there is a stats.lua in that same folder? If that file is not present, your installation is not correct. Perhaps the git clone failed.

You could try to start from scratch , removing everything from these locations inside your home folder:

  1. `.local/share/nvim/
  2. `.local/state/nvim/
  3. `.cache/nvim
sanevillain commented 11 months ago

@max397574 Updated the minimal setup. @abeldekat The file stats.lua is present on my system. I cleand both the .cache and state folder and most of the share folder, but since I've got some mason files in share folder used by my lunarvim config I didn't touch them. It's still failing with the same message.

Output of :checkhealth

lazy: require("lazy.health").check()

- ERROR Failed to run healthcheck for "lazy" plugin. Exception:
  ...ail/.local/share/nvim/lazy/lazy.nvim/lua/lazy/health.lua:1: module 'lazy.core.config' not found:
    no field package.preload['lazy.core.config']module 'LJK@/Users/denismail/.local/share/nvim/lazy/lazy.nvim/lua/lazy/core/config.lua~' not found:
    no field package.preload['LJK@/Users/denismail/.local/share/nvim/lazy/lazy.nvim/lua/lazy/core/config.lua~']
  cache_loader: module LJK@/Users/denismail/.local/share/nvim/lazy/lazy.nvim/lua/lazy/core/config.lua~ not found
  cache_loader_lib: module LJK@/Users/denismail/.local/share/nvim/lazy/lazy.nvim/lua/lazy/core/config.lua~ not found
    no file './LJK@/Users/denismail//local/share/nvim/lazy/lazy/nvim/lua/lazy/core/config/lua~.lua'
    no file '/Users/runner/work/neovim/neovim/.deps/usr/share/luajit-2.1/LJK@/Users/denismail//local/share/nvim/lazy/lazy/nvim/lua/lazy/core/config/lua~.lua'
    no file '/usr/local/share/lua/5.1/LJK@/Users/denismail//local/share/nvim/lazy/lazy/nvim/lua/lazy/core/config/lua~.lua'
    no file '/usr/local/share/lua/5.1/LJK@/Users/denismail//local/share/nvim/lazy/lazy/nvim/lua/lazy/core/config/lua~/init.lua'
    no file '/Users/runner/work/neovim/neovim/.deps/usr/share/lua/5.1/LJK@/Users/denismail//local/share/nvim/lazy/lazy/nvim/lua/lazy/core/config/lua~.lua'
    no file '/Users/runner/work/neovim/neovim/.deps/usr/share/lua/5.1/LJK@/Users/denismail//local/share/nvim/lazy/lazy/nvim/lua/lazy/core/config/lua~/init.lua'
    no file './LJK@/Users/denismail//local/share/nvim/lazy/lazy/nvim/lua/lazy/core/config/lua~.so'
    no file '/usr/local/lib/lua/5.1/LJK@/Users/denismail//local/share/nvim/lazy/lazy/nvim/lua/lazy/core/config/lua~.so'
    no file '/Users/runner/work/neovim/neovim/.deps/usr/lib/lua/5.1/LJK@/Users/denismail//local/share/nvim/lazy/lazy/nvim/lua/lazy/core/config/lua~.so'
    no file '/usr/local/lib/lua/5.1/loadall.so'
    no file './LJK@/Users/denismail/.so'
    no file '/usr/local/lib/lua/5.1/LJK@/Users/denismail/.so'
    no file '/Users/runner/work/neovim/neovim/.deps/usr/lib/lua/5.1/LJK@/Users/denismail/.so'
    no file '/usr/local/lib/lua/5.1/loadall.so'
  cache_loader_lib: module lazy.core.config not found
    no file './lazy/core/config.lua'
    no file '/Users/runner/work/neovim/neovim/.deps/usr/share/luajit-2.1/lazy/core/config.lua'
    no file '/usr/local/share/lua/5.1/lazy/core/config.lua'
    no file '/usr/local/share/lua/5.1/lazy/core/config/init.lua'
    no file '/Users/runner/work/neovim/neovim/.deps/usr/share/lua/5.1/lazy/core/config.lua'
    no file '/Users/runner/work/neovim/neovim/.deps/usr/share/lua/5.1/lazy/core/config/init.lua'
    no file './lazy/core/config.so'
    no file '/usr/local/lib/lua/5.1/lazy/core/config.so'
    no file '/Users/runner/work/neovim/neovim/.deps/usr/lib/lua/5.1/lazy/core/config.so'
    no file '/usr/local/lib/lua/5.1/loadall.so'
    no file './lazy.so'
    no file '/usr/local/lib/lua/5.1/lazy.so'
    no file '/Users/runner/work/neovim/neovim/.deps/usr/lib/lua/5.1/lazy.so'
    no file '/usr/local/lib/lua/5.1/loadall.so'

Pwd of lazy /Users/denismail/.local/share/nvim/lazy

Contents of lazy folder

.
ā””ā”€ā”€ lazy.nvim
    ā”œā”€ā”€ CHANGELOG.md
    ā”œā”€ā”€ LICENSE
    ā”œā”€ā”€ README.md
    ā”œā”€ā”€ TODO.md
    ā”œā”€ā”€ doc
    ā”‚Ā Ā  ā”œā”€ā”€ lazy.nvim.txt
    ā”‚Ā Ā  ā””ā”€ā”€ tags
    ā”œā”€ā”€ lua
    ā”‚Ā Ā  ā””ā”€ā”€ lazy
    ā”‚Ā Ā      ā”œā”€ā”€ core
    ā”‚Ā Ā      ā”œā”€ā”€ docs.lua
    ā”‚Ā Ā      ā”œā”€ā”€ example.lua
    ā”‚Ā Ā      ā”œā”€ā”€ health.lua
    ā”‚Ā Ā      ā”œā”€ā”€ help.lua
    ā”‚Ā Ā      ā”œā”€ā”€ init.lua
    ā”‚Ā Ā      ā”œā”€ā”€ manage
    ā”‚Ā Ā      ā”œā”€ā”€ state.lua
    ā”‚Ā Ā      ā”œā”€ā”€ stats.lua
    ā”‚Ā Ā      ā”œā”€ā”€ status.lua
    ā”‚Ā Ā      ā”œā”€ā”€ types.lua
    ā”‚Ā Ā      ā”œā”€ā”€ util.lua
    ā”‚Ā Ā      ā””ā”€ā”€ view
    ā”œā”€ā”€ selene.toml
    ā”œā”€ā”€ stylua.toml
    ā”œā”€ā”€ tests
    ā”‚Ā Ā  ā”œā”€ā”€ core
    ā”‚Ā Ā  ā”‚Ā Ā  ā”œā”€ā”€ e2e_spec.lua
    ā”‚Ā Ā  ā”‚Ā Ā  ā”œā”€ā”€ init_spec.lua
    ā”‚Ā Ā  ā”‚Ā Ā  ā”œā”€ā”€ plugin_spec.lua
    ā”‚Ā Ā  ā”‚Ā Ā  ā””ā”€ā”€ util_spec.lua
    ā”‚Ā Ā  ā”œā”€ā”€ handlers
    ā”‚Ā Ā  ā”‚Ā Ā  ā””ā”€ā”€ keys_spec.lua
    ā”‚Ā Ā  ā”œā”€ā”€ helpers.lua
    ā”‚Ā Ā  ā”œā”€ā”€ init.lua
    ā”‚Ā Ā  ā”œā”€ā”€ manage
    ā”‚Ā Ā  ā”‚Ā Ā  ā”œā”€ā”€ runner_spec.lua
    ā”‚Ā Ā  ā”‚Ā Ā  ā”œā”€ā”€ semver_spec.lua
    ā”‚Ā Ā  ā”‚Ā Ā  ā””ā”€ā”€ task_spec.lua
    ā”‚Ā Ā  ā””ā”€ā”€ run
    ā””ā”€ā”€ vim.toml

Is it somehow interfering with the other lazy installation that I have under /Users/denismail/.local/share/lunarvim/site/pack/lazy/opt/lazy.nvim ?

dpetka2001 commented 11 months ago

Just delete ~/.local/share/nvim/lazy/lazy.nvim folder, since that's the folder responsible for lazy.nvim itself and let Neovim re-install it after you restart.

sanevillain commented 11 months ago

@dpetka2001 I've done that multiple times, but to no avail, unfortunately. It's the same every time.

dpetka2001 commented 11 months ago

How do you start Neovim since you seem to have both a custom Neovim configuration and a Lunarvim configuration?

sanevillain commented 11 months ago

@dpetka2001 Lunarvim has an lvim command which starts nvim with the lunarvim environment and configuration and it uses that as its runtime path.

lvim() {
  nvim -u "$LUNARVIM_BASE_DIR/tests/minimal_init.lua" --cmd "set runtimepath+=$LUNARVIM_BASE_DIR" "$@"
}
max397574 commented 11 months ago

Idk if lunarvim uses packer or lazy.nvim but no matter what if it uses lazy.nvim you likely can't also install it yourself if it uses packer.nvim there is a chance that those two are conflicting

sanevillain commented 11 months ago

@max397574 It does use lazy. I suppose that there's some collision going on in there even if they both use different runtimepaths.

dpetka2001 commented 11 months ago

If Lunarvim uses a seperate directory under ~/.local/share to store its environment I don't see why there can't be different installations of lazy.nvim. That's also what happens when I test different configs with NVIM_APP_NAME. Each configuration goes to its own directory and has its own lazy.nvim installation and configuration. What should be clarified in regards to Lunarvim, is the location it uses to save the lazy.nvim repo.

sanevillain commented 11 months ago

@dpetka2001 I've shared it above. The installation location that is uses is the following $HOME/.local/share/lunarvim/site/pack/lazy/opt/lazy.nvim

dpetka2001 commented 11 months ago

Open Lunarvim and issue the following command :echo stdpath("data"). What is the output? Open your custom configuration Neovim and run the same command. Are the 2 outputs the same?

sanevillain commented 11 months ago

@dpetka2001 Yes, they are the same.

sanevillain commented 11 months ago

@dpetka2001 Internally it uses the custom runtimepath, but there are a couple of occasions in which it uses the default stdpath.

dpetka2001 commented 11 months ago

They shouldn't be the same. I have 2 configurations and they have different data paths. One is ~/.local/share/nvim (my default configuration) and the other one is ~/.local/share/lazyTest (my configuration for testing purposes). I don't know what you did and ended up with this situation, but my suggestion would be to start afresh, since this is definitely a Neovim misconfiguration from 2 different configs.

abeldekat commented 11 months ago

Could you try the following:

cd ~/.config
git clone https://github.com/lazyvim/starter.git lazytest
cd lazytest
NVIM_APPNAME=lazytest nvim init.lua

Reboot after installation. If the problem is LunarVim related, this should succeed:

NVIM_APPNAME=lazytest nvim init.lua

Edit:

What is the output of the following command:

alias | grep "nvim"

sanevillain commented 11 months ago

@abeldekat The test succeeded. The following command doesn't return anything. I guess that confirms it. My initial intuition told me that it might have something to do with my lunarvim setup. Any recommendations for creating a separate nvim environment ?

abeldekat commented 11 months ago

You have just done so....)

abeldekat commented 11 months ago

I would advise to completely uninstall LunarVim Then, confirm that nvim works as expected.

Than, install LunarVim once more. If this breaks the nvim command, create an issue in their github repro.

dpetka2001 commented 11 months ago

The test succeeds, because NVIM_APP_NAME makes sure to distinguish between different XDG_DATA_HOME directories from different configurations. The problem still remains, that your own custom configuration and Lunarvim are borked. You should start afresh.

abeldekat commented 11 months ago

Agreeing with @dpetka2001.

LunarVim and your custom nvim should be able to coexist.

abeldekat commented 11 months ago

But still, could this be a LunarVim issue?

sanevillain commented 11 months ago

@abeldekat I also don't know. The project hasn't been maintained much in awhile now, so it might be time to try out lazy.

dpetka2001 commented 11 months ago

No idea, never used it. echo stdpath("data") should not dabble with default XDG_DATA_HOME directory if they indeed use their own environment to store stuff. There may be some kind of misconfiguration on their part, but I can't say for sure since I've never used it.

sanevillain commented 11 months ago

@dpetka2001 The thing is that by looking at the source code I can see that they don't always use the "dedicated" path for lunarvim, but occasionally also the stdpath which might be the cause of the weird errors, since the majority of the codebase was written before the introduction of the path NVIM_APPNAME variable

dpetka2001 commented 11 months ago

I don't know what to tell you. I can only advocate in favor of LazyVim, since that's the distro I'm using and I think I got really lucky when deciding what to choose, because it's super simple and I've read quite a few things about other distros making things unnecessarily complicated on reddit. But I cannot talk about other distros since I've not tried them. Anyway whichever way you decide to go, I'd suggest reading more about NVIM_APP_NAME and how you can make use of it, since it allows you to have multiple configurations and they're all distinct from each other. That way you can make your own custom and test other distros as well without so much trouble. I believe this can be closed, since it's not really lazy.nvim related?

max397574 commented 11 months ago

@sanevillain why are you trying to install lazy.nvim anyway? you should just install plugins like explained here https://www.lunarvim.org/docs/configuration/plugins/user-plugins

dpetka2001 commented 11 months ago

This doesn't have to do with installing plugins. This has to do with him deciding to also make his own custom config along with Lunarvim. And in his own config he wanted to install lazy.nvim. They should be 2 different configurations with different XDG_DATA_HOME directories, so there isn't any conflict between them. That was the problem.

max397574 commented 11 months ago

well but that's not what you should do just make a "lunarvim" config and install plugins like this

if it would work then go for it if you want that but if it doesn't then this isn't a lazy.nvim issue nor a lunarvim issue because that's just not how it's intended to be used

sanevillain commented 11 months ago

@max397574 I just wanted to have another nvim environment that I can use.

max397574 commented 11 months ago

wym another environment? just use neovim with different configs which you can do with the nvim-appname thing and lunarvim separately

sanevillain commented 11 months ago

I will try to create a separate environment with the NVIM_APP_NAME method.

dpetka2001 commented 11 months ago

Please be aware that I misspoke earlier. The correct term is NVIM_APPNAME like @abeldekat used in the example above that you also tested. Just wanted to make sure you don't try something that is wrong.

sanevillain commented 11 months ago

Thank you guys for your help. I will try to remove my current lunarvim installation locally and see if I'll be able to do it afterwards.

dpetka2001 commented 11 months ago

Plz be kind and also close this issue, since it's not lazy.nvim related after all.