This may be a line endings issue, but not from Ubuntu. Make sure you have node
and npm
installed correctly:
- From WSL run
sudo apt install nodejs npm
to install node & npm - From PowerShell/CMD run
wsl --shutdown
to restart the WSL service - Next in WSL run
which npm
to confirm it’s installed [output: /usr/bin/npm]
Does the problem persist? Try this next:
Stop Windows path variables being shared with WSL by editing the /etc/wsl.conf
file in WSL. If the file doesn’t exist, execute sudo touch /etc/wsl.conf
first. Edit the file with the command sudo nano /etc/wsl.conf
and add the following configuration:
[interop]
appendWindowsPath = false
Then restart WSL2 with command wsl --shutdown
in Windows.
Note 1: This will stop the PATH environment variables from Windows passing through to WSL. Known bug: this stops the VSCode code .
command from working in WSL. If this is a problem, use NVM solution described here or switch to using node in a docker container.
Note 2: this also affects pyenv
command, see /usr/bin/env: ‘bash\r’: No such file or directory: Incompatible line-endings (WSL?)
Tip from @mike: “I did not want to disable the ability to do code .
so I just removed the windows nodejs path by adding this line to my ~/.bashrc PATH=$(echo “$PATH” | sed -e ‘s%:/mnt/c/Program Files/nodejs%%’)”