You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Neovim配置报错:stylua无法执行,寻求解决方案

解决null-ls提示stylua is not executable的问题

问题原因

Mason安装的二进制文件默认存放在~/.local/share/nvim/mason/bin目录下,这个路径未被加入系统$PATH环境变量时,null-ls无法定位到stylua可执行文件。

解决方案

方案1:将Mason的bin目录加入系统PATH

打开你的shell配置文件(如~/.bashrc、~/.zshrc或~/.fish/config.fish),添加以下内容:

export PATH="$HOME/.local/share/nvim/mason/bin:$PATH"

保存后重启shell,或执行source ~/.bashrc(对应你的shell配置文件)使更改生效。

方案2:在null-ls中直接指定stylua路径

修改config/null-ls.lua中的stylua配置,手动指定Mason安装的stylua路径:

null_ls.builtins.formatting.stylua.with({
    command = vim.fn.expand("~/.local/share/nvim/mason/bin/stylua"),
}),

替换原配置里的null_ls.builtins.formatting.stylua行即可。

额外验证步骤

  • 在Neovim中执行:Mason命令,找到stylua,确认其状态为Installed。
  • 在终端执行ls ~/.local/share/nvim/mason/bin/stylua,若能显示文件,说明路径无误。

内容的提问来源于stack exchange,提问作者Gaurang Shah

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.24 19:23:27