DEV Community

elizabeth
elizabeth

Posted on

CMD.EXE UNC Path Not Supported: Fix WSL npm Errors

You are in a WSL shell, inside your project directory, and npm run dev fails with this warning:

'\\wsl.localhost\Ubuntu\home\you\projects\my-app'
CMD.EXE was started with the above path as the current directory.
UNC paths are not supported. Defaulting to Windows directory.
Enter fullscreen mode Exit fullscreen mode

The path is correct. The problem is that a Windows npm is being asked to use a Linux directory as its working directory, and CMD.EXE cannot do that. It falls back to C:\Windows, so npm runs in the wrong place.

This tutorial shows how to confirm whether a Windows Node installation is shadowing your WSL toolchain, why CMD.EXE rejects the UNC path, and how to choose between three fixes: install Node inside WSL, move the project to a Windows drive path, or map the WSL share to a drive letter.

Table of Contents

What the warning means

A UNC path is a Windows network-style path that starts with two backslashes. WSL exposes Linux files to Windows at \\wsl.localhost\<distro>\... or the older \\wsl$\<distro>\.... Microsoft's WSL interop documentation describes this as the Windows view of the Linux filesystem and notes that Windows executables launched from WSL use the Windows PATH.

Two conditions must both be true for npm run dev to produce the warning:

  1. The npm resolved by your shell is a Windows installation, not a Linux one.
  2. That Windows process is started with your WSL directory as its current directory.

Remove either condition, and the warning goes away. That is why the fixes below take different approaches: one changes the npm toolchain, one changes the project location, and one changes how Windows sees the directory.

Step 1: Reproduce the npm failure

From the project directory in WSL, run:

cd ~/projects/my-app
npm run dev
Enter fullscreen mode Exit fullscreen mode

Capture the warning and, more importantly, the path in its first line:

'\\wsl.localhost\Ubuntu\home\you\projects\my-app'
CMD.EXE was started with the above path as the current directory.
UNC paths are not supported. Defaulting to Windows directory.
Enter fullscreen mode Exit fullscreen mode

The path may use \\wsl.localhost\ or \\wsl$\. Both are UNC paths, and both trigger the same fallback.

Also note the follow-on failure. npm may report that it cannot find package.json, may create files under C:\Windows, or may start a server from the wrong directory. Those are consequences of the fallback to C:\Windows, not separate npm bugs.

Step 2: Confirm CMD.EXE is falling back

Before blaming npm, test CMD.EXE by itself from the same WSL directory:

cd ~/projects/my-app
cmd.exe /c cd
Enter fullscreen mode Exit fullscreen mode

If the warning appears and the final line is C:\Windows, CMD.EXE has rejected the UNC working directory. That confirms the mechanism behind the npm error.

If it prints a C:\... path for your project without the warning, your project is already on a Windows drive and CMD.EXE is not falling back. In that case, the warning is coming from somewhere else, such as a shell startup script or an explicit cmd.exe call in package.json.

Step 3: Check whether npm is a Windows shim

Run several checks, because which only finds exact command names and can miss aliases or .cmd launchers:

which npm
which npm.cmd
which node
which node.exe
command -v npm
type -a npm
Enter fullscreen mode Exit fullscreen mode

Interpret the output like this:

Output Meaning
/mnt/c/Program Files/nodejs/npm or another /mnt/c/... path Windows npm
/home/you/.nvm/versions/node/.../bin/npm or /usr/bin/npm Linux npm
npm is aliased to ... A shell alias is intercepting the command
npm is a function A shell function is intercepting the command; inspect it with declare -f npm
which node finds nothing but which node.exe finds a Windows path Windows Node is present, but Linux Node is missing

which reports the first match in PATH. command -v is the POSIX shell check and may reveal aliases. In Bash, type -a is the most useful because it shows every match in order.

WSL adds Windows PATH entries to $PATH by default. WSL's configuration reference documents the appendWindowsPath setting, which defaults to true. That is why a Windows Node installation can become visible inside your Linux shell even when you did not intend to use it.

To see where the Windows entries sit:

echo "$PATH" | tr ':' '\n' | grep -n '/mnt/c'
Enter fullscreen mode Exit fullscreen mode

If the Windows Node directory appears before your nvm path, it wins. If no Linux npm appears at all, the Windows npm is not shadowing a Linux npm — it is the only one available. The diagnostic is the same either way.

A quick diagnosis table:

which npm cmd.exe /c cd What it means
/mnt/c/... C:\Windows Windows npm plus a UNC working directory — the most likely case
/home/... C:\Windows npm is Linux; the warning comes from another Windows tool or script
/mnt/c/... C:\Users\... Windows npm, but the project is on a Windows drive; no UNC warning, but the toolchain is still Windows

Why CMD.EXE rejects a UNC working directory

CMD.EXE tracks its current directory as a drive-based path. A UNC path has no drive letter, so CMD.EXE cannot hold it as the process working directory. It can still read from a UNC path passed as an argument — for example, dir \\wsl.localhost\Ubuntu\home\you — but it cannot make that path its current directory.

Microsoft's pushd documentation shows the workaround clearly: when given a network path, pushd temporarily assigns the highest unused drive letter and changes to that drive. That is CMD.EXE translating the UNC path into something it can use.

Explorer and PowerShell can hold a UNC location directly, which is why explorer.exe . works from a WSL directory while cmd.exe /c cd falls back. If you only need to browse the folder, you do not need CMD.EXE at all: you can open a WSL directory in File Explorer without cmd.exe by running explorer.exe . from the WSL prompt.

PowerShell can also start in a UNC directory, but that does not automatically make a Windows npm.cmd safe. A batch launcher still hands script execution to CMD.EXE. Decide based on the npm path and the actual warning, not on which Windows shell you launch.

Fix 1: Install Node.js and npm inside WSL

This is the best fix for normal WSL development because it removes CMD.EXE from the npm path entirely. Microsoft's guide to installing Node.js on WSL 2 recommends nvm and then verifying the result with which npm and which node. It also recommends keeping project files in the same filesystem as the Node installation. npm's installation docs likewise recommend a Node version manager over a standalone installer.

Install nvm, then Node.js and npm, inside WSL:

sudo apt-get update
sudo apt-get install -y curl
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/master/install.sh | bash
source ~/.bashrc
command -v nvm
Enter fullscreen mode Exit fullscreen mode

command -v nvm should print nvm. If it does not, close the terminal, reopen it, and try again. Then install the current LTS release:

nvm install --lts
nvm use --lts
node --version
npm --version
which npm
Enter fullscreen mode Exit fullscreen mode

which npm should now point inside /home/..., not /mnt/c/....

If you previously installed dependencies with the Windows npm, reinstall them with the Linux npm so native modules match the Linux platform:

cd ~/projects/my-app
rm -rf node_modules
npm install
npm run dev
Enter fullscreen mode Exit fullscreen mode

If which npm still resolves to /mnt/c, clear Bash's command cache and look for an alias or function:

hash -r
type -a npm
Enter fullscreen mode Exit fullscreen mode

Remove any npm alias or function from .bashrc, .zshrc, or your shell profile. Then open a fresh WSL shell.

Fix 2: Move the project to a Windows drive path

Use this fix only if you intentionally need to use the Windows Node installation, for example because a Windows-only native module or a corporate toolchain requires it.

Moving the project under /mnt/c gives Windows a drive-letter path. CMD.EXE sees C:\Users\you\projects\my-app instead of \\wsl.localhost\..., so the UNC warning disappears.

mkdir -p /mnt/c/Users/you/projects
cp -r ~/projects/my-app /mnt/c/Users/you/projects/
cd /mnt/c/Users/you/projects/my-app
rm -rf node_modules
npm install
npm run dev
Enter fullscreen mode Exit fullscreen mode

This approach follows one half of Microsoft's guidance on working across file systems: keep project files in the same filesystem as the toolchain, with Windows tools using Windows files and Linux tools using Linux files. It is coherent when the toolchain is Windows.

It is the wrong direction if you want to use Linux npm. Every Linux read of /mnt/c crosses the WSL filesystem boundary, which is significantly slower for installs, builds, and file watching. It also means node_modules may contain Windows-native binaries that will not work if you later switch back to Linux npm.

Fix 3: Map the WSL share to a drive letter

This is a short-term fix for running a Windows command against a WSL folder. It does not change your WSL shell's working directory, so it is best used from a native Windows Command Prompt.

Open a Windows Command Prompt — not a WSL tab — and run:

net use Z: \\wsl.localhost\Ubuntu\home\you\projects\my-app /persistent:no
Z:
npm run dev
Enter fullscreen mode Exit fullscreen mode

net use connects a shared resource to a drive letter. Microsoft's net use documentation describes assigning a device name such as Z: and using /persistent:no to avoid restoring the connection at the next logon. Clean up when you are finished:

net use Z: /delete
Enter fullscreen mode Exit fullscreen mode

Alternatively, use pushd, which creates a temporary drive mapping and removes it with popd:

pushd \\wsl.localhost\Ubuntu\home\you\projects\my-app
npm run dev
popd
Enter fullscreen mode Exit fullscreen mode

A mapping does not change the current directory of your WSL shell. If you launch cmd.exe from a WSL project path, it still starts with the UNC current directory and prints the warning before your net use or pushd command runs. Start from a native CMD.EXE window, or change to /mnt/c in WSL before launching CMD.EXE.

Also expect the mapped drive to be a Windows-only view. It may not appear as /mnt/z inside WSL, and it may break when the WSL distribution restarts.

Which fix should you use?

Situation Use
You develop in WSL and want npm to run natively Fix 1: install Node inside WSL
You need Windows Node because of a Windows-only dependency or policy Fix 2: keep the project on a Windows drive
You need one Windows command to run against a WSL folder Fix 3: map the share with net use or pushd

For most readers who hit this warning while running npm run dev, Fix 1 is the durable answer. The warning exists because the wrong npm is being used; installing the right one removes the entire class of problem.

Validate the fix in a fresh shell

Close all WSL terminals and reopen one. This clears cached command paths and reloads your shell configuration. Then check the project:

cd ~/projects/my-app
pwd
which npm
npm run dev
Enter fullscreen mode Exit fullscreen mode

For Fix 1, pwd should be under /home, which npm should point under /home or /usr, and npm run dev should start without the UNC warning. Running cmd.exe /c cd from that same Linux directory may still print C:\Windows; that is expected and does not matter if npm is now the Linux npm.

For Fix 2, pwd should start with /mnt/c, cmd.exe /c cd should print the corresponding C:\... path without a warning, and npm run dev should run from the Windows drive.

For Fix 3, start CMD.EXE from a native Windows prompt, switch to the mapped drive or use pushd, and confirm that npm run dev runs without the warning. Delete the mapping afterward if you used net use.

If the warning still appears with a Linux npm, check the project's scripts for explicit cmd.exe, .bat, or Windows-only tools. Also check npm's configured script shell:

npm config get script-shell
Enter fullscreen mode Exit fullscreen mode

If it returns a Windows cmd.exe path, remove the setting:

npm config delete script-shell
Enter fullscreen mode Exit fullscreen mode

Keep File Explorer working

explorer.exe . is independent of npm and CMD.EXE. It should still open the current WSL directory after any of these fixes. If it opens the wrong folder, confirm you are in the project directory and pass the Windows path explicitly:

pwd
explorer.exe "$(wslpath -w "$PWD")"
Enter fullscreen mode Exit fullscreen mode

wslpath -w converts the Linux path to its Windows UNC form, which Explorer handles natively. If opening Explorer produces the same CMD.EXE warning, the warning is coming from an alias, function, or terminal profile that invokes CMD.EXE — not from Explorer itself.

Conclusion

The CMD.EXE UNC warning is a working-directory problem, not a broken project path. Diagnose it in two steps: run cmd.exe /c cd to confirm that CMD.EXE is falling back to C:\Windows, then run which npm, which npm.cmd, and type -a npm to see whether a Windows Node installation is being used.

The best fix is to install Node.js and npm inside WSL with nvm, reinstall node_modules with the Linux npm, and verify that which npm points into your Linux home directory. Move the project to /mnt/c only when you intentionally need the Windows toolchain. Use net use or pushd only for one-off Windows commands against a WSL folder. Once the Linux npm is running the project, the warning disappears for the right reason.

Top comments (0)