Show JavaScript errors in Neovim on macOS
Written by strager on
Neovim is one of the most popular code editors, and JavaScript is one of the most popular programming languages. Let's look at some plugins to catch JavaScript bugs immediately in Neovim.
1. Install Homebrew
We are going to use the Homebrew package manager to install most of our tools. Installing Homebrew is simple: open Terminal.app (or iTerm 2 or any other terminal program) and paste the following command:
2. Install Neovim
Use Homebrew to install Neovim by running the following command in a terminal:
After installing Neovim, tell Neovim to use plugins installed through
Homebrew by adding the following line to your
~/.config/nvim/init.lua
file:
3. Install nvim-lspconfig
Next, we need to install the nvim-lspconfig Neovim plugin. This plugin lets you configure LSP servers, such as the JavaScript tool we're going to install later, in Neovim.
LSP servers provide diagnostics, completion, go-to-definition, and other features.
If you already use a Neovim plugin manager, install nvim-lspconfig using that plugin manager. Otherwise, run the following two commands in a terminal to install the plugin:
4. Install quick-lint-js
We're almost done! We now need to install quick-lint-js, which is the software which finds the errors in your JavaScript code. Install it using Homebrew by running the following commands in a terminal:
Then, add the following to your
~/.config/nvim/init.lua
file:
Restart Neovim and open a .js
file. Type something, and
you should see a warning:
If something doesn't work, see the troubleshooting steps below.
5. Customize & configure 🔧
Detect errors while you type
By default, nvim-lspconfig only shows you errors while in normal mode.
To show errors while you type in insert mode, add the following to
your ~/.config/nvim/init.lua
file:
Hide W
/E
sign in left gutter
By default, Neovim shows a symbol in the gutter to indicate an error.
If there is no error, the gutter is hidden. If you want the gutter to
always be hidden, add the following line to your
~/.config/nvim/init.lua
file:
Hide “■ error message” virtual text
By default, Neovim shows virtual text to the right of lines containing
errors. If there is no error, the virtual text is hidden. If you want
the error message virtual text to always be hidden, add the following
line to your ~/.config/nvim/init.lua
file:
vim.diagnostic.config({virtual_text = false})
6. Troubleshooting 🐞
“Spawning language server with cmd: `quick-lint-js` failed. The language server is either not installed, missing from PATH, or not executable.”
nvim-lspconfig gives this error if quick-lint-js was installed but
isn't in $PATH
.
-
Possible cause: Homebrew's directory was not added to
$PATH
during installation. -
Possible solution: Open a new terminal to reset
$PATH
. -
Possible solution: Run the following command to add
Homebrew's directory to
$PATH
:eval "\$(${HOMEBREW_PREFIX}/bin/brew shellenv)"
- Possible cause: quick-lint-js is not installed.
- Possible solution: Install quick-lint-js.
“E5113: Error while calling lua chunk: …/.config/nvim/init.lua: module 'lspconfig/quick_lint_js' not found”
Neovim gives this error if it can't find quick-lint-js' nvim-lspconfig configuration.
- Possible cause: quick-lint-js is not installed.
- Possible solution: Install quick-lint-js.
-
Possible cause: Neovim's
runtimepath
does not list Homebrew'sshare
directory. -
Possible solution:
In
init.lua
, add Homebrew'sshare
directory toruntimepath
. -
Possible solution: In
init.lua
, place theset runtimepath
command above therequire('lspconfig/quick_lint_js')
command.
If you have any corrections or need any help, please email me at strager.nds@gmail.com.