I’am trying to run a express server from a WSL terminal in VS Code.
However, whenever, I run the command npm run dev
I get the following error:
'\wsl$Ubuntuhomesimaolegalize-backend'
CMD.EXE was started with the above path as the current directory.
UNC paths are not supported. Defaulting to Windows directory.
I assume it has something to do with the path from windows to the folder in the WSL directory.
Which one is the right path format or what should I do to make this one valid ?
Searching I found that you can
You can solve this problem(UNC Paths not supported) by mapping a
normal drive letter to the path that has the UNC path.
But how do i map a normal drive letter to the path ?
2
Answers
This happens because whatever tool you are using is trying to run commands via
cmd.exe
andcmd.exe
does not understand UNC paths (those starting with\...
rather than drive letter). Mapping UNC path to drive will convert it to drive letter path.To map WSL path to Windows drive run
cmd.exe
(Command Line) and type following command:Where
X:
is drive that will be created (you’ll see it as network drive in e.g. My Computer) and\wsl$Ubuntuhomesimao
is WSL path to root of that drive.wsl$
is special hostname that tells Windows to connect to WSL,Ubuntu
is distribution name under WSL, then finallyhomesimao
is path to directory inUbuntu
distribution that should be mapped.I confronted the same situation yesterday. I assume maybe it was something wrong with my npm. Then I checked the npm path with
which npm
, and I found that my npm was mountedD:nodejsnpm
in Windows (exactly/mnt/d/nodejs/npm
in screen).I guess WSL uses CMD.exe to start npm from Windows described in
CMD.EXE was started with the above path as the current directory.
So maybe I can just install a new npm in WSL to solve this. Node Version Manager (nvm), is the most popular way to install multiple versions of Node.js. And each version of nodejs has its own version of npm. Just follow the link below.
Install nvm, node.js, and npm
Plus, if you have
Permission denied
, usenpm uninstall xxx
to remove your dependencies you’ve installed, and install your dependencies again.