npm not working in WSL2
When trying to run npm in WSL2 I got an error along these lines
/mnt/c/Program Files/nodejs/npm: /bin/sh^M: bad interpreter:
As the message indicates the problem is that WSL2 tries to run the Windows version of npm. You are supposed to be able to run Windows binaries from WSL2 but here there is some script involved (I think) that messes up.
Anyhow, the simplest fix is to just make sure that /usr/bin appears before Program Files in PATH:
PATH="$HOME/bin:$HOME/.local/bin:/usr/bin:$PATH"
Restart shell, or do that 'source' thing.
References: https://github.com/microsoft/WSL/issues/1512