6

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$\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 ?

4 Answers 4

8

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.

5

The error I had was because my ubuntu wsl was trying to use npm install on my windows, 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

ready you can run npm without problems

1
  • Installing npm in WSL with sudo apt install npm solved the problem. Oct 19 at 6:38
4

This happens because whatever tool you are using is trying to run commands via cmd.exe and cmd.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:

net use X: \\wsl$\Ubuntu\home\simao

Where X: is drive that will be created (you'll see it as network drive in e.g. My Computer) and \\wsl$\Ubuntu\home\simao 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 finally \home\simao is path to directory in Ubuntu distribution that should be mapped.

3
  • error: System error 67 has occurred. The network name cannot be found. Jul 11 at 2:08
  • @Sheldeeb This error occurs when your Windows network configuration is wrong or system policy prohibits mapping drives. My solution relies on that.
    – blami
    Jul 11 at 12:41
  • 2
    what exactly wrong in those configurations/ or what should I check for? Jul 13 at 12:17
-1

I had this error too. After making sure node and npm were installed on Ubuntu I was still getting the error when I ran npm run dev .

I realised I was in a virtual environment, so ran npm run dev outside of the virtual environment, in another terminal window and it finally worked.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.