I’m trying to run an express server from a WSL terminal in Visual Studio Code.
However, whenever, I run the command npm run dev, I get the following error:
'\\wsl$\Ubuntu\home\simao\legalize-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?
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 mounted D:\nodejs\npm 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, use npm uninstall xxx to remove your dependencies you've installed, and install your dependencies again.
The error I had was because my Ubuntu WSL was trying to use npm install on my Windows system. To validate it, execute the command:
which npm # output = /mnt/c/ubuntu/...
The expected output should be something like /usr/local7....
Solution: install npm directly on Ubuntu. You can do it using nvm:
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/master/install.sh | tried
source ~/.bashrc
When it is ready, you can run npm without problems.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With