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

cannot load the module, stack trace

Open blob42 opened this issue 2 years ago • 3 comments

Hi, thanks for the plugin, I cannot the plugin to load, I get the following error:

loop or previous error loading module 'chatgpt'
stack traceback:
	[C]: at 0x561fde6360f0

Using neovim v0.8.1 and packer

blob42 avatar Dec 17 '22 21:12 blob42

Is this still occurs? please make sure you are using the latest version and config is correct

jackMort avatar Dec 19 '22 07:12 jackMort

Yes still getting the same error, I tried on neovim versions 0.8.1 which is my daily driver as well as the nightly version. When I try to manually load the module from lua using require "chatgpt" I get the mentioned error.

For the config, I tried passing a copy of the sample config and the empty config dict {}, none of them works

Let me know if there is a way I can find more debug details

blob42 avatar Dec 22 '22 08:12 blob42

Try this one: #32 if error still occurs with latest version, paste output from :messages

jackMort avatar Dec 22 '22 10:12 jackMort

I'm getting this error too loading using the Lazy package manage

arjes avatar Dec 27 '22 20:12 arjes

I found somehow a way to get a more verbose error message:

E5108: Error executing lua ...site/pack/packer/opt/ChatGPT.nvim/lua/chatgpt/module.lua:11: module 'chatgpt.prompts' not
found:
        no field package.preload['chatgpt.prompts']
        no file './chatgpt/prompts.lua'
        no file '/home/runner/work/neovim/neovim/.deps/usr/share/luajit-2.1.0-beta3/chatgpt/prompts.lua'
        no file '/usr/local/share/lua/5.1/chatgpt/prompts.lua'
        no file '/usr/local/share/lua/5.1/chatgpt/prompts/init.lua'
        no file '/home/runner/work/neovim/neovim/.deps/usr/share/lua/5.1/chatgpt/prompts.lua'
        no file '/home/runner/work/neovim/neovim/.deps/usr/share/lua/5.1/chatgpt/prompts/init.lua'
        no file '/home/spike/.cache/nvim/packer_hererocks/2.1.0-beta3/share/lua/5.1/chatgpt/prompts.lua'
        no file '/home/spike/.cache/nvim/packer_hererocks/2.1.0-beta3/share/lua/5.1/chatgpt/prompts/init.lua'
        no file '/home/spike/.cache/nvim/packer_hererocks/2.1.0-beta3/lib/luarocks/rocks-5.1/chatgpt/prompts.lua'
        no file '/home/spike/.cache/nvim/packer_hererocks/2.1.0-beta3/lib/luarocks/rocks-5.1/chatgpt/prompts/init.lua'
        no file './chatgpt/prompts.so'
        no file '/usr/local/lib/lua/5.1/chatgpt/prompts.so'
        no file '/home/runner/work/neovim/neovim/.deps/usr/lib/lua/5.1/chatgpt/prompts.so'
        no file '/usr/local/lib/lua/5.1/loadall.so'
        no file '/home/spike/.cache/nvim/packer_hererocks/2.1.0-beta3/lib/lua/5.1/chatgpt/prompts.so'
        no file './chatgpt.so'
        no file '/usr/local/lib/lua/5.1/chatgpt.so'
        no file '/home/runner/work/neovim/neovim/.deps/usr/lib/lua/5.1/chatgpt.so'
        no file '/usr/local/lib/lua/5.1/loadall.so'
        no file '/home/spike/.cache/nvim/packer_hererocks/2.1.0-beta3/lib/lua/5.1/chatgpt.so'
stack traceback:
        [C]: in function 'require'
        ...site/pack/packer/opt/ChatGPT.nvim/lua/chatgpt/module.lua:11: in main chunk
        [C]: in function 'require'
        ...e/nvim/site/pack/packer/opt/ChatGPT.nvim/lua/chatgpt.lua:2: in main chunk
        [C]: in function 'require'
        [string ":lua"]:1: in main chunk

blob42 avatar Jan 03 '23 09:01 blob42

I am also getting this error with packer+windows/wsl

piyushdivyankar1994 avatar Jan 20 '23 05:01 piyushdivyankar1994

Same error here using Lazy as a plugin manager

Error executing Lua callback: .../share/nvim/lazy/lazy.nvim/lua/lazy/core/handler/cmd.lua:18: nvim_exec(): Vim:Error executing Lua callback: ...n/.local/share/nvim/lazy/ChatGPT.nvim/plugin/chatgpt.lua:2: loop or previous error loading module 'chatgpt'
stack traceback:
        [C]: in function 'require'
        ...n/.local/share/nvim/lazy/ChatGPT.nvim/plugin/chatgpt.lua:2: in function <...n/.local/share/nvim/lazy/ChatGPT.nvim/plugin/chatgpt.lua:1>
        [C]: in function 'cmd'
        .../share/nvim/lazy/lazy.nvim/lua/lazy/core/handler/cmd.lua:18: in function <.../share/nvim/lazy/lazy.nvim/lua/lazy/core/handler/cmd.lua:16>
stack traceback:
        [C]: in function 'cmd'
        .../share/nvim/lazy/lazy.nvim/lua/lazy/core/handler/cmd.lua:18: in function <.../share/nvim/lazy/lazy.nvim/lua/lazy/core/handler/cmd.lua:16>
:version
NVIM v0.9.0-dev-740+g2c1e7242f
Build type: RelWithDebInfo
LuaJIT 2.1.0-beta3

RRikor avatar Jan 29 '23 14:01 RRikor

Problem solved since the last recently after I updated the plugin probably. Now I could get a clean message asking to put the openai api key in the environment and all works fine.

blob42 avatar Jan 29 '23 23:01 blob42

For those who are using packer and lazy loading, it was a pain to make it load ChatGPT without error. I'm leaving the solution here: in my packer conf

    ["MunifTanjim/nui.nvim"] = {
        module = {"nui.layout", "nui.popup"},
        module_pattern = {"nui.*"}
    },

    ["jackMort/ChatGPT.nvim"] = {
        opt = true,
        keys = {"<leader>gpt"},
        module_pattern = {"chatgpt*"},
        after = {"nui.nvim", "telescope.nvim"},
        setup = function()
            require("custom.plugins.configs.chat-gpt").load_api_key()
        end,
        config = function()
            require("custom.plugins.configs.chat-gpt").setup()
        end,
        requires = {
            "MunifTanjim/nui.nvim",
            "nvim-lua/plenary.nvim",
            "nvim-telescope/telescope.nvim"
        }
    },

my chat-gpt custom config:

local M = {}

M.load_api_key = function()
    local openai_api_key_path = vim.fn.expand('$XDG_CONFIG_HOME') .. '/openai/token'
    local openai_api_key = vim.fn.readfile(openai_api_key_path, '', 1)
    vim.fn.setenv('OPENAI_API_KEY', openai_api_key[1])
end



local config = {
    ...
}

M.setup = function()
    local ok, chatgpt = pcall(require, 'chatgpt')
    if not ok then
        vim.notify("missing module chatgpt", vim.log.levels.WARN)
        return
    end
    chatgpt.setup(config)
end


return M

blob42 avatar Jan 30 '23 20:01 blob42

Thank you for this @blob42 ! I modified your code for my own uses but it got the plugin working for me! :)

For anyone wondering, I just changed things to match how we setup plugins by default for Packer:

    use({
        "MunifTanjim/nui.nvim",
        module = {"nui.layout", "nui.popup"},
        module_pattern = {"nui.*"}
    })

    use ({
        "jackMort/ChatGPT.nvim",
        opt = true,
        keys = {"<leader>gpt"},
        module_pattern = {"chatgpt*"},
        after = {"nui.nvim", "telescope.nvim"},
        setup = function()
            require("user.plugins.chatgpt").load_api_key()
        end,
        config = function()
            require("user.plugins.chatgpt").setup()
        end,
        requires = {
            "MunifTanjim/nui.nvim",
            "nvim-lua/plenary.nvim",
            "nvim-telescope/telescope.nvim"
        }
    })

Also I changed the load_api_key function:

-- In my chatgpt.lua  #module
M.load_api_key = function()
    vim.fn.setenv('OPENAI_API_KEY', os.getenv("OPENAI_API_KEY"))
end

Karsteski avatar Mar 19 '23 15:03 Karsteski

Can we get a more descriptive error message? when the env variable (api key) is missing? Just saying

E5108: Error executing lua [string ":lua"]:1: loop or previous error loading module 'chatgpt'

is not enough to tell what's wrong with the config/setup. (I think this issue needs to be reopened)

wookayin avatar Apr 14 '23 10:04 wookayin

Can we get a more descriptive error message? when the env variable (api key) is missing? Just saying

E5108: Error executing lua [string ":lua"]:1: loop or previous error loading module 'chatgpt'

is not enough to tell what's wrong with the config/setup. (I think this issue needs to be reopened)

Please reopen this issue. For NvChad user, I totally has no clue why it failed to load. I am also trying the solution from other thread but nor solved. :(

basheewang avatar Apr 17 '23 08:04 basheewang