packer.nvim icon indicating copy to clipboard operation
packer.nvim copied to clipboard

Bootstrapping doesn't work

Open simonmandlik opened this issue 3 years ago • 11 comments

  • nvim --version: v0.6.0
  • git --version: 2.32.0 (Apple Git-132)
  • Operating system/version: Mac OS Monterey 12.1
  • Terminal name/version: iterm2 3.4.15

Bootstrapping suggested in README throws an error on a fresh installation.

Steps to reproduce

~/.config/nvim/init.vim:

lua require('plugins')

~/.config/nvim/lua/plugins.lua:

local fn = vim.fn
local install_path = fn.stdpath('data')..'/site/pack/packer/start/packer.nvim'
if fn.empty(fn.glob(install_path)) > 0 then
  packer_bootstrap = fn.system({'git', 'clone', '--depth', '1', 'https://github.com/wbthomason/packer.nvim', install_path})
end

require('packer').startup(function(use)
  use 'wbthomason/packer.nvim'

  -- Automatically set up your configuration after cloning packer.nvim
  -- Put this at the end after all plugins
  if packer_bootstrap then
    require('packer').sync()
  end
end)

~/.local/share/nvim and ~/.config/nvim/pluginn are both empty

Actual behaviour

Error detected while processing /Users/simon.mandlik/.config/nvim/init.vim:
line   10:
E5108: Error executing lua /Users/simon.mandlik/.config/nvim/lua/plugins.lua:7: module 'packer' not found:
        no field package.preload['packer']
        no file './packer.lua'
        no file '/usr/local/Cellar/luajit-openresty/2.1-20210510/share/luajit-2.1.0-beta3/packer.lua'
        no file '/usr/local/share/lua/5.1/packer.lua'
        no file '/usr/local/share/lua/5.1/packer/init.lua'
        no file '/usr/local/Cellar/luajit-openresty/2.1-20210510/share/lua/5.1/packer.lua'
        no file '/usr/local/Cellar/luajit-openresty/2.1-20210510/share/lua/5.1/packer/init.lua'
        no file './packer.so'
        no file '/usr/local/lib/lua/5.1/packer.so'
        no file '/usr/local/Cellar/luajit-openresty/2.1-20210510/lib/lua/5.1/packer.so'
        no file '/usr/local/lib/lua/5.1/loadall.so'
stack traceback:
        [C]: in function 'require'
        /Users/simon.mandlik/.config/nvim/lua/plugins.lua:7: in main chunk
        [C]: in function 'require'
        [string ":lua"]:1: in main chunk

simonmandlik avatar Dec 29 '21 13:12 simonmandlik

I solved not loaded packer module with

  vim.cmd 'packadd packer.nvim'

after packer_bootstrap = ... line but anyway sync, update, install functions doesn't work without arguments

guess it's load modules before executing config, so clonning repo on the run doesn't add it to loaded packages and you need to do it manually

l4zygreed avatar Jan 02 '22 17:01 l4zygreed

I think the issue is that, in the new version, vim.fn.stdpath('data') .. '/site/pack/*/start/*' is not added to the runtime path if the site directory is not yet created when you open neovim. I have fixed the issue by adding the following inside the bootstrapping if:

local rtp_addition = vim.fn.stdpath('data') .. '/site/pack/*/start/*'
if not string.find(vim.o.runtimepath, rtp_addition) then
  vim.o.runtimepath = rtp_addition .. ',' .. vim.o.runtimepath
end

Alternatively, this is shorter and should also work:

vim.o.runtimepath = vim.fn.stdpath('data') .. '/site/pack/*/start/*,' .. vim.o.runtimepath

oscarbenedito avatar Jan 05 '22 20:01 oscarbenedito

I think the issue is that, in the new version, `vim.fn.stdpath('data') ..

I believe this should be added to the bootstrapping documentation.

EDIT: I've also seen the other solution which uses packadd and /opt/ instead of /start/ so I won't make a pull request since I'm not sure exactly which is better.

punowo avatar Jan 10 '22 23:01 punowo

I was able to make it work with the solution proposed by @oscarbenedito

That is, adding

vim.o.runtimepath = vim.fn.stdpath('data') .. '/site/pack/*/start/*,' .. vim.o.runtimepath

to the bootstrapping condition.

franciscoj avatar Jan 21 '22 21:01 franciscoj

This seems to be a regression with Neovim core - @mjlbach confirmed that this does not reproduce on v0.6.1.

wbthomason avatar Feb 11 '22 00:02 wbthomason

I can reproduce on v0.7.0.

getkey avatar May 07 '22 21:05 getkey

This works for me!

local fn = vim.fn
local install_path = fn.stdpath('data')..'/site/pack/packer/start/packer.nvim'
if fn.empty(fn.glob(install_path)) > 0 then
   packer_bootstrap = fn.system({'git', 'clone', '--depth', '1', 'https://github.com/wbthomason/packer.nvim', install_path})
   vim.o.runtimepath = vim.fn.stdpath('data') .. '/site/pack/*/start/*,' .. vim.o.runtimepath
end

return require('packer').startup(function(use)
   -- make sure to add this line to let packer manage itself
   use 'wbthomason/packer.nvim'

   -- Automatically set up your configuration after cloning packer.nvim
   -- Put this at the end after all plugins
   if packer_bootstrap then
     require('packer').sync()
   end
end)

References: https://github.com/wbthomason/packer.nvim/issues/701#issuecomment-1046245015 & https://github.com/wbthomason/packer.nvim/issues/750#issuecomment-1006070458

Animeshz avatar May 18 '22 13:05 Animeshz

This works for me!

local fn = vim.fn
local install_path = fn.stdpath('data')..'/site/pack/packer/start/packer.nvim'
if fn.empty(fn.glob(install_path)) > 0 then
   packer_bootstrap = fn.system({'git', 'clone', '--depth', '1', 'https://github.com/wbthomason/packer.nvim', install_path})
   vim.o.runtimepath = vim.fn.stdpath('data') .. '/site/pack/*/start/*,' .. vim.o.runtimepath
end

return require('packer').startup(function(use)
   -- make sure to add this line to let packer manage itself
   use 'wbthomason/packer.nvim'

   -- Automatically set up your configuration after cloning packer.nvim
   -- Put this at the end after all plugins
   if packer_bootstrap then
     require('packer').sync()
   end
end)

References: #701 (comment) & #750 (comment)

Does not work for me I get the error:

E5112: Error while creating lua chunk: XXX/.config/nvim/init.lua:133: '<eof>' expected near 'vim'

I am using neovim nightly

616b2f avatar May 25 '22 12:05 616b2f

I compiled from head yesterday and had to removed the return before require in that second chunk of that code. This allowed the bootstrapping to occur successfully

klmanion avatar May 31 '22 14:05 klmanion

I'm still having this issue - packer tries to remove itself every time neovim is started, and no matter what I say (y/N), spits out a nasty error:

Error in coroutine: ...e/nvim/site/pack/packer/start/packer
.nvim/lua/packer.lua:630: attempt to index local 'display_win' (a nil value)
  • nvim --version
NVIM v0.8.0
Build type: Release
LuaJIT 2.1.0-beta3
Compiled by [email protected]

Features: +acl +iconv +tui
See ":help feature-compile"

   system vimrc file: "$VIM/sysinit.vim"
  fall-back for $VIM: "/opt/homebrew/Cellar/neovim/0.8.0/share/nvim"

Run :checkhealth for more info

ghost avatar Oct 24 '22 03:10 ghost

Update: this issue was fixed for me by repairing a misconfigured wildignore option in my init.lua, seen in #1108.

ghost avatar Oct 30 '22 22:10 ghost