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
相关产品推荐
相关产品推荐

