WebStorm can't find node interpreter

Viewed 1125

I'm running Manjaro, I have node in PATH, it's located at /usr/bin/node and I can invoke it from the terminal using node, as expected. But when I try to add the interpreter to WebStorm, when I open the dialog for adding Node & npm executables and navigate to /usr/bin, it simply doesn't show up there. I've installed WebStorm through flatpak. Any ideas?

2 Answers

Managed to fix this by uninstalling the flatpak WebStorm instance that I had installed and installed WebStorm through Snap store. It simply worked afterwards, but I'll keep the question open in case anyone has a better solution.

Flatpak is sandboxed, so it cannot directly run anything that is on the host, outside of the user's home directory.

However, there is a way to get around this, by having flatpak run the host binary using the flatpak-spawn.


Solution

1. Run these two commands in shell:

printf '#!/usr/bin/env sh\nflatpak-spawn --host node "$@"\n' > ~/flatpak-node
chmod a+x ~/flatpak-node

2. In WebStorm, go to

File > Settings > Languages & Frameworks > Node.js and NPM (or TypeScript)

and set the Node Interpreter to ~/flatpak-node.


Explanation

This will create an executable file called flatpak-node in your home directory, with this content:

#!/usr/bin/env sh
flatpak-spawn --host node "$@"

This will tell Flatpak to run the node binary on the host and pass along any parameters. It works because the executable we created is in the home directory, and flatpak-spawn can run the command as if it was on the host (outside of the sandbox).

Personally, I make the file ~/bin/flatpak-node, but you can put it anywhere in the home directory.


Bonus PHP

Of note is this same solution works for PhpStorm and the php interpreter. Simply replace node with php in the content and filename:

#!/usr/bin/env sh
flatpak-spawn --host php "$@"
Related