LunarVim中用nvim-dap调试Vite React TS项目的连接错误排查
Firefox Debug Adapter 连接失败与Neovim帮助命令报错问题
环境与已做配置
已通过Mason界面安装firefox-debug-adapter,并在LunarVim配置文件中添加以下配置:
local dap = require('dap') dap.adapters.firefox = { type = 'executable', command = 'node', args = { os.getenv('HOME') .. '/.local/share/nvim/mason/packages/firefox-debug-adapter/dist/adapter.bundle.js' }, } dap.configurations.typescriptreact = { { name = 'Debug with Firefox', type = 'firefox', request = 'launch', reAttach = true, url = 'http://localhost:5173', webRoot = '${workspaceFolder}', firefoxExecutable = '/opt/firefox/firefox' } }
问题现象
- 启动Vite开发服务器、设置断点并通过dap-ui启动调试后,Firefox打开并加载应用,但Neovim弹出错误:
Debug adapter didn't respond. Either the adapter is slow (then wait and ignore this) or there is a problem with your adapter or `firefox` configuration. Check the logs for errors (:help dap.set_log_level) Press ENTER or type command to continue // 已按回车 Error on launch: connect ECONNREFUSED ::1:6000 Press ENTER or type command to continue // 再次按回车
- 执行
:help dap.set_log_level命令时,弹出Tree-sitter相关错误:
Error detected while processing FileType Autocommands for "*": Error executing lua callback: /usr/share/nvim/runtime/lua/vim/treesitter/query.lua:219: query: invalid node type at position 14 for language help stack traceback: [C]: in function '_ts_parse_query' /usr/share/nvim/runtime/lua/vim/treesitter/query.lua:219: in function 'get_query' /usr/share/nvim/runtime/lua/vim/treesitter/languagetree.lua:52: in function 'new' /usr/share/nvim/runtime/lua/vim/treesitter.lua:45: in function '_create_parser' /usr/share/nvim/runtime/lua/vim/treesitter.lua:96: in function 'get_parser' .../start/nvim-treesitter/lua/nvim-treesitter/highlight.lua:34: in function 'start' .../start/nvim-treesitter/lua/nvim-treesitter/highlight.lua:42: in function 'attach' ...er/start/nvim-treesitter/lua/nvim-treesitter/configs.lua:505: in function 'attach_module' ...er/start/nvim-treesitter/lua/nvim-treesitter/configs.lua:528: in function 'reattach_module' ...er/start/nvim-treesitter/lua/nvim-treesitter/configs.lua:131: in function <...er/start/nvim-treesitter/lua/nvim-treesitter/configs.lua:130>
已确认firefox-debug-adapter的路径无误,请求解决上述问题。
解决步骤
1. 修复Debug Adapter连接拒绝(ECONNREFUSED ::1:6000)
- 显式配置调试端口与IPv4:修改dap配置,强制使用IPv4并指定端口,同时跳过浏览器内置文件避免阻塞:
dap.configurations.typescriptreact = { { name = 'Debug with Firefox', type = 'firefox', request = 'launch', reAttach = true, url = 'http://localhost:5173', webRoot = '${workspaceFolder}', firefoxExecutable = '/opt/firefox/firefox', port = 6000, host = '127.0.0.1', -- 禁用IPv6,强制用IPv4 skipFiles = { '**/node_modules/**', '**/chrome/**', '**/content/**', '**/lib/**' } } } - 检查端口占用:执行
lsof -i :6000或ss -tulpn | grep 6000,如果有其他进程占用该端口,终止进程或更换端口号。 - 关闭Firefox隐私窗口:隐私模式会阻止远程调试连接,确保所有Firefox窗口都是普通模式。
2. 修复:help dap.set_log_level的Tree-sitter错误
- 更新help语言解析器:在Neovim中执行
:TSUpdate help,专门更新help文件的Tree-sitter解析规则。 - 临时禁用help文件的Tree-sitter高亮:在配置中添加以下代码,避免解析错误:
vim.api.nvim_create_autocmd('FileType', { pattern = 'help', callback = function() vim.treesitter.stop() end }) - 重装nvim-treesitter(若更新无效):先执行
:TSUninstall all,再执行:TSInstall all(或只安装常用语言),重置插件解析规则。
内容的提问来源于stack exchange,提问作者linusw
相关产品推荐
相关产品推荐

