How to Fix Neovim Markdown Preview Failing to Open in WSL 2
Once in a while you may try to preview a Markdown file and it fails by printing the Node version.
I’ve been using this Markdown Preview plugin with Vim for years and it just so happens LazyVim uses it too with Neovim. It’s great.
I noticed once in a while when I run :MarkdowPreview
, instead of it opening
my default browser and showing a preview, Neovim instead displays the Node
version.
There’s an open issue on GitHub about this but there’s many different replies which are related to having a Node environment that may not be set up correctly.
What if you’re sure your Node environment is good to go and this plugin worked fine for you in the past?
It might be your copy of WSL 2 temporarily acting up. You can verify this by
trying to run explorer.exe .
or any other command that involves running a
Windows binary.
If you get an error saying exec format error: explorer.exe
, this is the
problem. The good news is all you have to do is restart WSL 2. You can run wsl --shutdown
from PowerShell and then open a new WSL 2 prompt and you should be
good to go.
I’m not sure what causes that, but the takeaway here is the Markdown plugin is working normally. Something just got temporarily messed up with WSL 2 as a whole.
It’s happened to me enough times now where I figured making this post is worth it. It’s not very often but maybe once every few months.
# Demo Video
Timestamps
- 0:12 – It doesn’t preview
- 0:43 – GitHub issue
- 1:03 – I think it’s a bug with WSL 2
- 1:57 – Restart WSL 2 to fix it
Have you ever had this happen with WSL 2 on your end? Let us know below.