ChatGPT.nvim
ChatGPT.nvim copied to clipboard
cannot load the module, stack trace
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
Is this still occurs? please make sure you are using the latest version and config is correct
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
Try this one: #32 if error still occurs with latest version, paste output from :messages
I'm getting this error too loading using the Lazy package manage
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
I am also getting this error with packer+windows/wsl
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
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.
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
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
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)
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. :(