luaneovimpacker

NVIM not sourcing Packer


I'm trying to install nvim/packer onto my machine but I'm getting an error for some reason.

Error detected while processing :source (no file):
E5108: Error executing lua [string ":source (no file)"]:6: module 'packer' not found:                                                                                       no field package.preload['packer']
        no file './packer.lua'
        no file '/data/data/com.termux/files/usr/share/luajit-2.1.0-beta3/packer.l
ua'
        no file '/usr/local/share/lua/5.1/packer.lua'
        no file '/usr/local/share/lua/5.1/packer/init.lua'
        no file '/data/data/com.termux/files/usr/share/lua/5.1/packer.lua'
        no file '/data/data/com.termux/files/usr/share/lua/5.1/packer/init.lua'
        no file './packer.so'
        no file '/usr/local/lib/lua/5.1/packer.so'
        no file '/data/data/com.termux/files/usr/lib/lua/5.1/packer.so'
        no file '/usr/local/lib/lua/5.1/loadall.so'
stack traceback:
        [C]: in function 'require'
        [string ":source (no file)"]:6: in main chunk

This is what's in my packer.lua file:

-- This file can be loaded by calling `lua require('plugins')` from your init.vim

-- Only required if you have packer configured as `opt`
-- vim.cmd([[packadd packer.nvim]])

return require("packer").startup(function(use)
        -- Packer can manage itself
        use("wbthomason/packer.nvim")
end)

I'm not entirely sure why it's erroring. I'm trying to use termux on my android tablet which may be the cause however I'm getting this on a windows 10 machine as well. However I'm not getting it on a windows 11 machine. I'm not sure what I should be doing to solve this error?

Thanks, Mitchell


Solution

  • I solved this by using this snippet from the repos github page:

    local ensure_packer = function()
      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
        fn.system({'git', 'clone', '--depth', '1', 'https://github.com/wbthomason/packer.nvim', install_path})
        vim.cmd [[packadd packer.nvim]]
        return true
      end
      return false
    end
    
    local packer_bootstrap = ensure_packer()
    
    return require('packer').startup(function(use)
      use 'wbthomason/packer.nvim'
      -- My plugins here
      -- use 'foo1/bar1.nvim'
      -- use 'foo2/bar2.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)
    

    It seems I just wasn't installing packer at all...