<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: elizabeth</title>
    <description>The latest articles on DEV Community by elizabeth (@elizabeth_1).</description>
    <link>https://dev.to/elizabeth_1</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F4265244%2F0b6b03d8-2729-4471-a89b-ad2b05606c4e.png</url>
      <title>DEV Community: elizabeth</title>
      <link>https://dev.to/elizabeth_1</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/elizabeth_1"/>
    <language>en</language>
    <item>
      <title>CMD.EXE UNC Path Not Supported: Fix WSL npm Errors</title>
      <dc:creator>elizabeth</dc:creator>
      <pubDate>Sun, 29 Nov 2026 21:09:53 +0000</pubDate>
      <link>https://dev.to/elizabeth_1/cmdexe-unc-path-not-supported-fix-wsl-npm-errors-1kc9</link>
      <guid>https://dev.to/elizabeth_1/cmdexe-unc-path-not-supported-fix-wsl-npm-errors-1kc9</guid>
      <description>&lt;p&gt;You are in a WSL shell, inside your project directory, and &lt;code&gt;npm run dev&lt;/code&gt; fails with this warning:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;'\\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.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



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

&lt;p&gt;This tutorial shows how to confirm whether a Windows Node installation is shadowing your WSL toolchain, why &lt;code&gt;CMD.EXE&lt;/code&gt; 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.&lt;/p&gt;

&lt;h2&gt;
  
  
  Table of Contents
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;What the warning means&lt;/li&gt;
&lt;li&gt;Step 1: Reproduce the npm failure&lt;/li&gt;
&lt;li&gt;Step 2: Confirm CMD.EXE is falling back&lt;/li&gt;
&lt;li&gt;Step 3: Check whether npm is a Windows shim&lt;/li&gt;
&lt;li&gt;Why CMD.EXE rejects a UNC working directory&lt;/li&gt;
&lt;li&gt;Fix 1: Install Node.js and npm inside WSL&lt;/li&gt;
&lt;li&gt;Fix 2: Move the project to a Windows drive path&lt;/li&gt;
&lt;li&gt;Fix 3: Map the WSL share to a drive letter&lt;/li&gt;
&lt;li&gt;Which fix should you use?&lt;/li&gt;
&lt;li&gt;Validate the fix in a fresh shell&lt;/li&gt;
&lt;li&gt;Keep File Explorer working&lt;/li&gt;
&lt;li&gt;Conclusion&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  What the warning means
&lt;/h2&gt;

&lt;p&gt;A UNC path is a Windows network-style path that starts with two backslashes. WSL exposes Linux files to Windows at &lt;code&gt;\\wsl.localhost\&amp;lt;distro&amp;gt;\...&lt;/code&gt; or the older &lt;code&gt;\\wsl$\&amp;lt;distro&amp;gt;\...&lt;/code&gt;. &lt;a href="https://learn.microsoft.com/en-us/windows/dev-environment/wsl-interop" rel="noopener noreferrer"&gt;Microsoft's WSL interop documentation&lt;/a&gt; describes this as the Windows view of the Linux filesystem and notes that Windows executables launched from WSL use the Windows &lt;code&gt;PATH&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Two conditions must both be true for &lt;code&gt;npm run dev&lt;/code&gt; to produce the warning:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;The &lt;code&gt;npm&lt;/code&gt; resolved by your shell is a Windows installation, not a Linux one.&lt;/li&gt;
&lt;li&gt;That Windows process is started with your WSL directory as its current directory.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;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.&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 1: Reproduce the npm failure
&lt;/h2&gt;

&lt;p&gt;From the project directory in WSL, run:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;cd&lt;/span&gt; ~/projects/my-app
npm run dev
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Capture the warning and, more importantly, the path in its first line:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;'\\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.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The path may use &lt;code&gt;\\wsl.localhost\&lt;/code&gt; or &lt;code&gt;\\wsl$\&lt;/code&gt;. Both are UNC paths, and both trigger the same fallback.&lt;/p&gt;

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

&lt;h2&gt;
  
  
  Step 2: Confirm CMD.EXE is falling back
&lt;/h2&gt;

&lt;p&gt;Before blaming npm, test &lt;code&gt;CMD.EXE&lt;/code&gt; by itself from the same WSL directory:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;cd&lt;/span&gt; ~/projects/my-app
cmd.exe /c &lt;span class="nb"&gt;cd&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If the warning appears and the final line is &lt;code&gt;C:\Windows&lt;/code&gt;, &lt;code&gt;CMD.EXE&lt;/code&gt; has rejected the UNC working directory. That confirms the mechanism behind the npm error.&lt;/p&gt;

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

&lt;h2&gt;
  
  
  Step 3: Check whether npm is a Windows shim
&lt;/h2&gt;

&lt;p&gt;Run several checks, because &lt;code&gt;which&lt;/code&gt; only finds exact command names and can miss aliases or &lt;code&gt;.cmd&lt;/code&gt; launchers:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;which npm
which npm.cmd
which node
which node.exe
&lt;span class="nb"&gt;command&lt;/span&gt; -v npm
&lt;span class="nb"&gt;type&lt;/span&gt; -a npm
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Interpret the output like this:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Output&lt;/th&gt;
&lt;th&gt;Meaning&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;code&gt;/mnt/c/Program Files/nodejs/npm&lt;/code&gt; or another &lt;code&gt;/mnt/c/...&lt;/code&gt; path&lt;/td&gt;
&lt;td&gt;Windows npm&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;code&gt;/home/you/.nvm/versions/node/.../bin/npm&lt;/code&gt; or &lt;code&gt;/usr/bin/npm&lt;/code&gt;
&lt;/td&gt;
&lt;td&gt;Linux npm&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;npm is aliased to ...&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;A shell alias is intercepting the command&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;npm is a function&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;A shell function is intercepting the command; inspect it with &lt;code&gt;declare -f npm&lt;/code&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;code&gt;which node&lt;/code&gt; finds nothing but &lt;code&gt;which node.exe&lt;/code&gt; finds a Windows path&lt;/td&gt;
&lt;td&gt;Windows Node is present, but Linux Node is missing&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

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

&lt;p&gt;WSL adds Windows &lt;code&gt;PATH&lt;/code&gt; entries to &lt;code&gt;$PATH&lt;/code&gt; by default. &lt;a href="https://learn.microsoft.com/en-us/windows/wsl/wsl-config" rel="noopener noreferrer"&gt;WSL's configuration reference&lt;/a&gt; documents the &lt;code&gt;appendWindowsPath&lt;/code&gt; setting, which defaults to &lt;code&gt;true&lt;/code&gt;. That is why a Windows Node installation can become visible inside your Linux shell even when you did not intend to use it.&lt;/p&gt;

&lt;p&gt;To see where the Windows entries sit:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="s2"&gt;"$PATH"&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt; tr &lt;span class="s1"&gt;':'&lt;/span&gt; &lt;span class="s1"&gt;'\n'&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt; grep -n &lt;span class="s1"&gt;'/mnt/c'&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;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.&lt;/p&gt;

&lt;p&gt;A quick diagnosis table:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;&lt;code&gt;which npm&lt;/code&gt;&lt;/th&gt;
&lt;th&gt;&lt;code&gt;cmd.exe /c cd&lt;/code&gt;&lt;/th&gt;
&lt;th&gt;What it means&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;/mnt/c/...&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;C:\Windows&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Windows npm plus a UNC working directory — the most likely case&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;/home/...&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;C:\Windows&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;npm is Linux; the warning comes from another Windows tool or script&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;/mnt/c/...&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;C:\Users\...&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Windows npm, but the project is on a Windows drive; no UNC warning, but the toolchain is still Windows&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;h2&gt;
  
  
  Why CMD.EXE rejects a UNC working directory
&lt;/h2&gt;

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

&lt;p&gt;&lt;a href="https://learn.microsoft.com/en-us/windows-server/administration/windows-commands/pushd" rel="noopener noreferrer"&gt;Microsoft's &lt;code&gt;pushd&lt;/code&gt; documentation&lt;/a&gt; shows the workaround clearly: when given a network path, &lt;code&gt;pushd&lt;/code&gt; temporarily assigns the highest unused drive letter and changes to that drive. That is &lt;code&gt;CMD.EXE&lt;/code&gt; translating the UNC path into something it can use.&lt;/p&gt;

&lt;p&gt;Explorer and PowerShell can hold a UNC location directly, which is why &lt;code&gt;explorer.exe .&lt;/code&gt; works from a WSL directory while &lt;code&gt;cmd.exe /c cd&lt;/code&gt; falls back. If you only need to browse the folder, you do not need &lt;code&gt;CMD.EXE&lt;/code&gt; at all: you can &lt;a href="https://linuxgeek.org/blog/how-to-open-windows-explorer-from-current-working-directory-of-wsl-shell/" rel="noopener noreferrer"&gt;open a WSL directory in File Explorer without cmd.exe&lt;/a&gt; by running &lt;code&gt;explorer.exe .&lt;/code&gt; from the WSL prompt.&lt;/p&gt;

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

&lt;h2&gt;
  
  
  Fix 1: Install Node.js and npm inside WSL
&lt;/h2&gt;

&lt;p&gt;This is the best fix for normal WSL development because it removes &lt;code&gt;CMD.EXE&lt;/code&gt; from the npm path entirely. &lt;a href="https://learn.microsoft.com/en-us/windows/dev-environment/javascript/nodejs-on-wsl" rel="noopener noreferrer"&gt;Microsoft's guide to installing Node.js on WSL 2&lt;/a&gt; recommends nvm and then verifying the result with &lt;code&gt;which npm&lt;/code&gt; and &lt;code&gt;which node&lt;/code&gt;. It also recommends keeping project files in the same filesystem as the Node installation. &lt;a href="https://docs.npmjs.com/cli/v11/configuring-npm/install" rel="noopener noreferrer"&gt;npm's installation docs&lt;/a&gt; likewise recommend a Node version manager over a standalone installer.&lt;/p&gt;

&lt;p&gt;Install nvm, then Node.js and npm, inside WSL:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;sudo apt-get update
sudo apt-get install -y curl
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/master/install.sh &lt;span class="o"&gt;|&lt;/span&gt; bash
&lt;span class="nb"&gt;source&lt;/span&gt; ~/.bashrc
&lt;span class="nb"&gt;command&lt;/span&gt; -v nvm
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;command -v nvm&lt;/code&gt; should print &lt;code&gt;nvm&lt;/code&gt;. If it does not, close the terminal, reopen it, and try again. Then install the current LTS release:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;nvm install --lts
nvm use --lts
node --version
npm --version
which npm
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;which npm&lt;/code&gt; should now point inside &lt;code&gt;/home/...&lt;/code&gt;, not &lt;code&gt;/mnt/c/...&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;If you previously installed dependencies with the Windows npm, reinstall them with the Linux npm so native modules match the Linux platform:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;cd&lt;/span&gt; ~/projects/my-app
rm -rf node_modules
npm install
npm run dev
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If &lt;code&gt;which npm&lt;/code&gt; still resolves to &lt;code&gt;/mnt/c&lt;/code&gt;, clear Bash's command cache and look for an alias or function:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;hash&lt;/span&gt; -r
&lt;span class="nb"&gt;type&lt;/span&gt; -a npm
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Remove any &lt;code&gt;npm&lt;/code&gt; alias or function from &lt;code&gt;.bashrc&lt;/code&gt;, &lt;code&gt;.zshrc&lt;/code&gt;, or your shell profile. Then open a fresh WSL shell.&lt;/p&gt;

&lt;h2&gt;
  
  
  Fix 2: Move the project to a Windows drive path
&lt;/h2&gt;

&lt;p&gt;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.&lt;/p&gt;

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

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;mkdir -p /mnt/c/Users/you/projects
cp -r ~/projects/my-app /mnt/c/Users/you/projects/
&lt;span class="nb"&gt;cd&lt;/span&gt; /mnt/c/Users/you/projects/my-app
rm -rf node_modules
npm install
npm run dev
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This approach follows one half of &lt;a href="https://learn.microsoft.com/en-us/windows/wsl/filesystems" rel="noopener noreferrer"&gt;Microsoft's guidance on working across file systems&lt;/a&gt;: 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.&lt;/p&gt;

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

&lt;h2&gt;
  
  
  Fix 3: Map the WSL share to a drive letter
&lt;/h2&gt;

&lt;p&gt;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.&lt;/p&gt;

&lt;p&gt;Open a Windows Command Prompt — not a WSL tab — and run:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;net use Z: \\wsl.localhost\Ubuntu\home\you\projects\my-app /persistent:no
Z:
npm run dev
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;net use&lt;/code&gt; connects a shared resource to a drive letter. &lt;a href="https://learn.microsoft.com/en-us/previous-versions/windows/it-pro/windows-xp/bb490717%28v=technet.10%29" rel="noopener noreferrer"&gt;Microsoft's &lt;code&gt;net use&lt;/code&gt; documentation&lt;/a&gt; describes assigning a device name such as &lt;code&gt;Z:&lt;/code&gt; and using &lt;code&gt;/persistent:no&lt;/code&gt; to avoid restoring the connection at the next logon. Clean up when you are finished:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;net use Z: /delete
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Alternatively, use &lt;code&gt;pushd&lt;/code&gt;, which creates a temporary drive mapping and removes it with &lt;code&gt;popd&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;pushd \\wsl.localhost\Ubuntu\home\you\projects\my-app
npm run dev
popd
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



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

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

&lt;h2&gt;
  
  
  Which fix should you use?
&lt;/h2&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Situation&lt;/th&gt;
&lt;th&gt;Use&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;You develop in WSL and want npm to run natively&lt;/td&gt;
&lt;td&gt;Fix 1: install Node inside WSL&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;You need Windows Node because of a Windows-only dependency or policy&lt;/td&gt;
&lt;td&gt;Fix 2: keep the project on a Windows drive&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;You need one Windows command to run against a WSL folder&lt;/td&gt;
&lt;td&gt;Fix 3: map the share with &lt;code&gt;net use&lt;/code&gt; or &lt;code&gt;pushd&lt;/code&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;For most readers who hit this warning while running &lt;code&gt;npm run dev&lt;/code&gt;, 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.&lt;/p&gt;

&lt;h2&gt;
  
  
  Validate the fix in a fresh shell
&lt;/h2&gt;

&lt;p&gt;Close all WSL terminals and reopen one. This clears cached command paths and reloads your shell configuration. Then check the project:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;cd&lt;/span&gt; ~/projects/my-app
&lt;span class="nb"&gt;pwd&lt;/span&gt;
which npm
npm run dev
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



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

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

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

&lt;p&gt;If the warning still appears with a Linux npm, check the project's scripts for explicit &lt;code&gt;cmd.exe&lt;/code&gt;, &lt;code&gt;.bat&lt;/code&gt;, or Windows-only tools. Also check npm's configured script shell:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;npm config get script-shell
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If it returns a Windows &lt;code&gt;cmd.exe&lt;/code&gt; path, remove the setting:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;npm config delete script-shell
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Keep File Explorer working
&lt;/h2&gt;

&lt;p&gt;&lt;code&gt;explorer.exe .&lt;/code&gt; is independent of npm and &lt;code&gt;CMD.EXE&lt;/code&gt;. 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:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;pwd&lt;/span&gt;
explorer.exe &lt;span class="s2"&gt;"$(wslpath -w "&lt;/span&gt;&lt;span class="nv"&gt;$PWD&lt;/span&gt;&lt;span class="s2"&gt;")"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



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

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

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

&lt;p&gt;The best fix is to install Node.js and npm inside WSL with nvm, reinstall &lt;code&gt;node_modules&lt;/code&gt; with the Linux npm, and verify that &lt;code&gt;which npm&lt;/code&gt; points into your Linux home directory. Move the project to &lt;code&gt;/mnt/c&lt;/code&gt; only when you intentionally need the Windows toolchain. Use &lt;code&gt;net use&lt;/code&gt; or &lt;code&gt;pushd&lt;/code&gt; 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.&lt;/p&gt;

</description>
      <category>debugging</category>
      <category>linux</category>
      <category>node</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>explorer.exe Exit Code 1 in WSL: Fix BROWSER False Failure</title>
      <dc:creator>elizabeth</dc:creator>
      <pubDate>Fri, 27 Nov 2026 21:04:24 +0000</pubDate>
      <link>https://dev.to/elizabeth_1/explorerexe-exit-code-1-in-wsl-fix-browser-false-failure-hf6</link>
      <guid>https://dev.to/elizabeth_1/explorerexe-exit-code-1-in-wsl-fix-browser-false-failure-hf6</guid>
      <description>&lt;p&gt;You set &lt;code&gt;BROWSER=explorer.exe&lt;/code&gt;, run a CLI that wants to open a sign-in page, and the Windows browser opens — then the CLI says no browser opened. The launch worked; the status check did not. This tutorial shows how to reproduce that false failure, why &lt;code&gt;explorer.exe&lt;/code&gt; returns 1 after a successful hand-off, and how to build a small &lt;code&gt;BROWSER&lt;/code&gt; wrapper that accepts only that hand-off status while still propagating real errors. It also tests the wrapper under &lt;code&gt;set -e&lt;/code&gt; and shows where to export it.&lt;/p&gt;

&lt;h2&gt;
  
  
  Table of Contents
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Reproduce the False Failure&lt;/li&gt;
&lt;li&gt;Why Explorer Returns Exit Code 1&lt;/li&gt;
&lt;li&gt;Build a Status-Aware BROWSER Wrapper&lt;/li&gt;
&lt;li&gt;Test the Wrapper Without Masking Errors&lt;/li&gt;
&lt;li&gt;Export BROWSER Safely and Verify It&lt;/li&gt;
&lt;li&gt;What the Wrapper Cannot Fix&lt;/li&gt;
&lt;li&gt;Conclusion&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Reproduce the False Failure
&lt;/h2&gt;

&lt;p&gt;Start with the launcher by itself:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;set&lt;/span&gt; +e
explorer.exe https://example.com
&lt;span class="nb"&gt;printf&lt;/span&gt; &lt;span class="s1"&gt;'explorer status: %d\n'&lt;/span&gt; &lt;span class="s2"&gt;"$?"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;On an affected WSL setup, the default Windows browser opens and the status is 1. That is the whole mismatch in one command: the URL reached Windows, but the Linux process saw a non-zero exit.&lt;/p&gt;

&lt;p&gt;Now put it behind &lt;code&gt;BROWSER&lt;/code&gt; the way a CLI sees it:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;set&lt;/span&gt; +e
&lt;span class="kd"&gt;export&lt;/span&gt; &lt;span class="nv"&gt;BROWSER&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;explorer.exe
&lt;span class="s2"&gt;"$BROWSER"&lt;/span&gt; https://example.com
&lt;span class="nv"&gt;status&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="nv"&gt;$?&lt;/span&gt;
&lt;span class="nb"&gt;set&lt;/span&gt; -e
&lt;span class="nb"&gt;printf&lt;/span&gt; &lt;span class="s1"&gt;'BROWSER status: %d\n'&lt;/span&gt; &lt;span class="s2"&gt;"$status"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The browser still opens, and the status is still 1. A CLI that treats any non-zero status as failure will report “no browser opened” and may tell you to set &lt;code&gt;BROWSER&lt;/code&gt;, even though it is already set. &lt;a href="https://github.com/Pseudogiant-xr/Pseudolife-MCP/issues/1615" rel="noopener noreferrer"&gt;A bug report for the Pseudolife-MCP console&lt;/a&gt; documents exactly this pattern: &lt;code&gt;export BROWSER=explorer.exe&lt;/code&gt; opens the browser, then the console prints &lt;code&gt;explorer.exe failed (exit status: 1)&lt;/code&gt; and advises setting &lt;code&gt;BROWSER&lt;/code&gt;. The report is useful because it separates the launch from the status check.&lt;/p&gt;

&lt;p&gt;Use this quick diagnosis before building anything:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;What you see&lt;/th&gt;
&lt;th&gt;What it means&lt;/th&gt;
&lt;th&gt;What to do&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Browser opens, status 1&lt;/td&gt;
&lt;td&gt;Explorer hand-off, false failure&lt;/td&gt;
&lt;td&gt;Build the wrapper&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Browser opens, status 0&lt;/td&gt;
&lt;td&gt;No exit-code problem&lt;/td&gt;
&lt;td&gt;Check the CLI’s detection logic&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Browser does not open, status 1&lt;/td&gt;
&lt;td&gt;Real launch problem&lt;/td&gt;
&lt;td&gt;Fix the URL, interop, or default browser&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;code&gt;explorer.exe&lt;/code&gt; not found or 127&lt;/td&gt;
&lt;td&gt;WSL interop or Windows PATH&lt;/td&gt;
&lt;td&gt;Fix interop first&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;If &lt;code&gt;command -v explorer.exe&lt;/code&gt; prints nothing, the wrapper cannot help. &lt;a href="https://learn.microsoft.com/en-us/windows/dev-environment/wsl-interop" rel="noopener noreferrer"&gt;Microsoft’s WSL interop documentation&lt;/a&gt; explains that Windows executables are called by their full name, including &lt;code&gt;.exe&lt;/code&gt;, and resolve through the Windows PATH rather than the Linux PATH. Fix that first.&lt;/p&gt;

&lt;p&gt;Also test the exact URL your CLI uses, not just &lt;code&gt;https://example.com&lt;/code&gt;. Query strings and fragments can behave differently, and a hand-off status cannot tell you that the right page actually rendered.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why Explorer Returns Exit Code 1
&lt;/h2&gt;

&lt;p&gt;&lt;code&gt;explorer.exe&lt;/code&gt; is a Windows shell process, not a console browser. When WSL starts it, Explorer hands the URL to Windows and the default browser opens. The Linux process sees Explorer’s exit status, not the browser’s. On affected WSL builds, that hand-off status is 1 even though the browser opened. The MCP console report treats that 1 as a failure; that is the false negative.&lt;/p&gt;

&lt;p&gt;“Hand-off” is the key word: Explorer passed the target to Windows and exited. It does not mean the browser finished loading the page, and it does not report the browser’s own status.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;set -e&lt;/code&gt; turns the false negative into an abrupt exit. &lt;a href="https://www.gnu.org/software/bash/manual/html_node/The-Set-Builtin.html" rel="noopener noreferrer"&gt;The Bash manual’s description of &lt;code&gt;set -e&lt;/code&gt;&lt;/a&gt; says the shell exits immediately when a simple command returns non-zero, with exceptions for commands in &lt;code&gt;if&lt;/code&gt; or &lt;code&gt;while&lt;/code&gt; tests, &lt;code&gt;&amp;amp;&amp;amp;&lt;/code&gt; or &lt;code&gt;||&lt;/code&gt; lists, and commands inverted with &lt;code&gt;!&lt;/code&gt;. A CLI that runs &lt;code&gt;$BROWSER "$url"&lt;/code&gt; as an ordinary command under &lt;code&gt;set -e&lt;/code&gt; can exit before its own error handling runs.&lt;/p&gt;

&lt;p&gt;Tools that launch the browser in the background have a similar problem. A settle window is a short delay a launcher waits before deciding the browser did not start. The MCP console report says its POSIX launcher treats any non-zero exit inside a 2-second settle window as failure. Explorer exits 1 quickly after the hand-off, so the health check fires even though the page opened.&lt;/p&gt;

&lt;p&gt;The tempting one-line fix is:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="kd"&gt;export&lt;/span&gt; &lt;span class="nv"&gt;BROWSER&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s1"&gt;'explorer.exe || true'&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Do not use it. &lt;code&gt;BROWSER&lt;/code&gt; is a command value, not a shell expression. &lt;a href="https://manpages.opensuse.org/Tumbleweed/xdg-utils/xdg-open.1.en.html" rel="noopener noreferrer"&gt;The &lt;code&gt;xdg-open&lt;/code&gt; manual’s description of &lt;code&gt;BROWSER&lt;/code&gt;&lt;/a&gt; says the value is split on spaces, quoting is not supported, and the URL is appended as the last argument. It also supports a colon-separated fallback list and a &lt;code&gt;%s&lt;/code&gt; placeholder. With &lt;code&gt;explorer.exe || true&lt;/code&gt;, a consumer that does not run a shell can pass &lt;code&gt;||&lt;/code&gt; and &lt;code&gt;true&lt;/code&gt; as literal arguments, or append the URL after &lt;code&gt;true&lt;/code&gt;. Either way, the launch is no longer reliable.&lt;/p&gt;

&lt;p&gt;Even at the call site, &lt;code&gt;"$BROWSER" "$url" || true&lt;/code&gt; hides every failure: missing Explorer, disabled interop, permission errors, and genuine launch failures. You want to ignore only the status that means “handed off.”&lt;/p&gt;

&lt;h2&gt;
  
  
  Build a Status-Aware BROWSER Wrapper
&lt;/h2&gt;

&lt;p&gt;Create a small executable that validates the target, checks that Explorer exists, accepts 0 and 1, and propagates everything else.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;mkdir -p &lt;span class="s2"&gt;"$HOME/.local/bin"&lt;/span&gt;
cat &lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="s2"&gt;"$HOME/.local/bin/wsl-browser"&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&amp;lt;&lt;/span&gt;&lt;span class="s1"&gt;'EOF'&lt;/span&gt;
&lt;span class="c"&gt;#!/bin/bash&lt;/span&gt;
&lt;span class="c"&gt;# Launch an HTTP(S) URL in the Windows default browser from WSL.&lt;/span&gt;
&lt;span class="c"&gt;# explorer.exe can return 1 after a successful hand-off, so 1 is&lt;/span&gt;
&lt;span class="c"&gt;# accepted here. Other non-zero statuses are real failures.&lt;/span&gt;

&lt;span class="nb"&gt;set&lt;/span&gt; -u

&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="o"&gt;[&lt;/span&gt; &lt;span class="s2"&gt;"$#"&lt;/span&gt; -ne 1 &lt;span class="o"&gt;]&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt; &lt;span class="k"&gt;then&lt;/span&gt;
  &lt;span class="nb"&gt;printf&lt;/span&gt; &lt;span class="s1"&gt;'wsl-browser: expected exactly one URL, got %d argument(s)\n'&lt;/span&gt; &lt;span class="s2"&gt;"$#"&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&amp;amp;&lt;/span&gt;2
  &lt;span class="nb"&gt;exit&lt;/span&gt; 2
&lt;span class="k"&gt;fi&lt;/span&gt;

&lt;span class="nv"&gt;url&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="nv"&gt;$1&lt;/span&gt;
&lt;span class="k"&gt;case&lt;/span&gt; &lt;span class="s2"&gt;"$url"&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt;
  http://*&lt;span class="o"&gt;|&lt;/span&gt;https://*&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;;&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
  *&lt;span class="o"&gt;)&lt;/span&gt;
    &lt;span class="nb"&gt;printf&lt;/span&gt; &lt;span class="s1"&gt;'wsl-browser: refusing non-HTTP(S) target: %s\n'&lt;/span&gt; &lt;span class="s2"&gt;"$url"&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&amp;amp;&lt;/span&gt;2
    &lt;span class="nb"&gt;exit&lt;/span&gt; 2
    &lt;span class="o"&gt;;&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;esac&lt;/span&gt;

&lt;span class="k"&gt;if&lt;/span&gt; ! &lt;span class="nb"&gt;command&lt;/span&gt; -v explorer.exe &lt;span class="o"&gt;&amp;gt;&lt;/span&gt;/dev/null 2&lt;span class="o"&gt;&amp;gt;&amp;amp;&lt;/span&gt;1&lt;span class="o"&gt;;&lt;/span&gt; &lt;span class="k"&gt;then&lt;/span&gt;
  &lt;span class="nb"&gt;printf&lt;/span&gt; &lt;span class="s1"&gt;'wsl-browser: explorer.exe not found; check WSL interop and PATH\n'&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&amp;amp;&lt;/span&gt;2
  &lt;span class="nb"&gt;exit&lt;/span&gt; 127
&lt;span class="k"&gt;fi&lt;/span&gt;

&lt;span class="k"&gt;if&lt;/span&gt; explorer.exe &lt;span class="s2"&gt;"$url"&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt; &lt;span class="k"&gt;then&lt;/span&gt;
  &lt;span class="nb"&gt;exit&lt;/span&gt; 0
&lt;span class="k"&gt;else&lt;/span&gt;
  &lt;span class="nv"&gt;status&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="nv"&gt;$?&lt;/span&gt;
  &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="o"&gt;[&lt;/span&gt; &lt;span class="s2"&gt;"$status"&lt;/span&gt; -eq 1 &lt;span class="o"&gt;]&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt; &lt;span class="k"&gt;then&lt;/span&gt;
    &lt;span class="c"&gt;# Explorer's hand-off status on affected WSL builds.&lt;/span&gt;
    &lt;span class="nb"&gt;exit&lt;/span&gt; 0
  &lt;span class="k"&gt;fi&lt;/span&gt;
  &lt;span class="nb"&gt;printf&lt;/span&gt; &lt;span class="s1"&gt;'wsl-browser: explorer.exe failed with status %d\n'&lt;/span&gt; &lt;span class="s2"&gt;"$status"&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&amp;amp;&lt;/span&gt;2
  &lt;span class="nb"&gt;exit&lt;/span&gt; &lt;span class="s2"&gt;"$status"&lt;/span&gt;
&lt;span class="k"&gt;fi&lt;/span&gt;
EOF
chmod +x &lt;span class="s2"&gt;"$HOME/.local/bin/wsl-browser"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Check the syntax:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;bash -n &lt;span class="s2"&gt;"$HOME/.local/bin/wsl-browser"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Why this shape:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The &lt;code&gt;case&lt;/code&gt; rejects missing and non-HTTP(S) targets before Explorer runs. A malformed argument is a real usage error, not a hand-off.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;command -v&lt;/code&gt; turns missing Explorer or broken interop into 127 instead of a false success.&lt;/li&gt;
&lt;li&gt;The &lt;code&gt;if explorer.exe&lt;/code&gt; context lets the wrapper inspect the status without &lt;code&gt;set -e&lt;/code&gt; aborting the script. The wrapper itself does not use &lt;code&gt;set -e&lt;/code&gt;; it needs to handle the status.&lt;/li&gt;
&lt;li&gt;Only 0 and 1 return success. 2, 126, 127, and anything else propagate unchanged.&lt;/li&gt;
&lt;li&gt;There is no global &lt;code&gt;|| true&lt;/code&gt;.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;If your Explorer returns 0, the wrapper passes that through too. The wrapper does not make Explorer’s status truthful; it translates the known ambiguous status into the answer the CLI needs.&lt;/p&gt;

&lt;p&gt;If you are still deciding between the direct &lt;code&gt;explorer.exe&lt;/code&gt; one-liner, the &lt;code&gt;BROWSER&lt;/code&gt; export, &lt;code&gt;wslview&lt;/code&gt;, and an &lt;code&gt;open&lt;/code&gt; shim, &lt;a href="https://linuxgeek.org/blog/open-browser-in-host-system-from-windows-subsystem-for-linux/" rel="noopener noreferrer"&gt;the four methods for opening the host browser from WSL&lt;/a&gt; explain the launch mechanics; this wrapper adds status handling on top.&lt;/p&gt;

&lt;p&gt;The wrapper is URL-only on purpose. If your tool also opens local HTML files, add a path branch that translates the Linux path with &lt;code&gt;wslpath -w&lt;/code&gt; before passing it to Explorer. Keep the wrapper path free of spaces, because &lt;code&gt;BROWSER&lt;/code&gt; consumers may split the value on spaces.&lt;/p&gt;

&lt;h2&gt;
  
  
  Test the Wrapper Without Masking Errors
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Test 1: a valid URL under set -e
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;set&lt;/span&gt; -e
&lt;span class="kd"&gt;export&lt;/span&gt; &lt;span class="nv"&gt;BROWSER&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"$HOME/.local/bin/wsl-browser"&lt;/span&gt;
&lt;span class="s2"&gt;"$BROWSER"&lt;/span&gt; https://example.com
&lt;span class="nb"&gt;printf&lt;/span&gt; &lt;span class="s1"&gt;'still running\n'&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The browser should open and &lt;code&gt;still running&lt;/code&gt; should print. Without the wrapper, the same sequence with &lt;code&gt;BROWSER=explorer.exe&lt;/code&gt; would stop at Explorer’s status 1. This is the exact regression the wrapper fixes.&lt;/p&gt;

&lt;h3&gt;
  
  
  Test 2: an invalid target
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;set&lt;/span&gt; +e
&lt;span class="s2"&gt;"$BROWSER"&lt;/span&gt; &lt;span class="s1"&gt;'not a URL'&lt;/span&gt;
&lt;span class="nb"&gt;printf&lt;/span&gt; &lt;span class="s1"&gt;'status=%d\n'&lt;/span&gt; &lt;span class="s2"&gt;"$?"&lt;/span&gt;
&lt;span class="nb"&gt;set&lt;/span&gt; -e
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Expected: status 2, and no browser launch. The wrapper rejects the target before calling Explorer.&lt;/p&gt;

&lt;h3&gt;
  
  
  Test 3: Explorer is not available
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;set&lt;/span&gt; +e
&lt;span class="nv"&gt;PATH&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;/usr/bin:/bin &lt;span class="s2"&gt;"$BROWSER"&lt;/span&gt; https://example.com
&lt;span class="nb"&gt;printf&lt;/span&gt; &lt;span class="s1"&gt;'status=%d\n'&lt;/span&gt; &lt;span class="s2"&gt;"$?"&lt;/span&gt;
&lt;span class="nb"&gt;set&lt;/span&gt; -e
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Expected: status 127. This simulates a shell where &lt;code&gt;explorer.exe&lt;/code&gt; is not on PATH, for example because interop is disabled or Windows PATH is not appended. A bare &lt;code&gt;|| true&lt;/code&gt; would have turned this into success.&lt;/p&gt;

&lt;h3&gt;
  
  
  Test 4: Explorer returns a different error
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nv"&gt;tmp&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="nv"&gt;$(&lt;/span&gt;mktemp -d&lt;span class="o"&gt;)&lt;/span&gt;
&lt;span class="nb"&gt;printf&lt;/span&gt; &lt;span class="s1"&gt;'#!/bin/sh\nexit 3\n'&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="s2"&gt;"$tmp/explorer.exe"&lt;/span&gt;
chmod +x &lt;span class="s2"&gt;"$tmp/explorer.exe"&lt;/span&gt;
&lt;span class="nb"&gt;set&lt;/span&gt; +e
&lt;span class="nv"&gt;PATH&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"$tmp:$PATH"&lt;/span&gt; &lt;span class="s2"&gt;"$BROWSER"&lt;/span&gt; https://example.com
&lt;span class="nv"&gt;status&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="nv"&gt;$?&lt;/span&gt;
&lt;span class="nb"&gt;set&lt;/span&gt; -e
&lt;span class="nb"&gt;printf&lt;/span&gt; &lt;span class="s1"&gt;'status=%d\n'&lt;/span&gt; &lt;span class="s2"&gt;"$status"&lt;/span&gt;
rm -rf &lt;span class="s2"&gt;"$tmp"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Expected: status 3. This proves the wrapper does not hide every failure. The MCP console report’s own test plan uses the same idea: a &lt;code&gt;/bin/sh&lt;/code&gt; stub named &lt;code&gt;explorer.exe&lt;/code&gt; that exits 1, plus a second stub with a different name that exits 1 and must still be reported as a failure.&lt;/p&gt;

&lt;p&gt;Run the real-browser test manually. For CI, use stubs so no test opens a real browser.&lt;/p&gt;

&lt;h2&gt;
  
  
  Export BROWSER Safely and Verify It
&lt;/h2&gt;

&lt;p&gt;Use an absolute path, because &lt;code&gt;BROWSER&lt;/code&gt; values are split on spaces and some tools do not search an interactive shell’s PATH.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="c"&gt;# ~/.bashrc or ~/.zshrc&lt;/span&gt;
&lt;span class="kd"&gt;export&lt;/span&gt; &lt;span class="nv"&gt;BROWSER&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"$HOME/.local/bin/wsl-browser"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Reload the file and confirm the value:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;source&lt;/span&gt; ~/.bashrc   &lt;span class="c"&gt;# or source ~/.zshrc&lt;/span&gt;
&lt;span class="nb"&gt;printf&lt;/span&gt; &lt;span class="s1"&gt;'%s\n'&lt;/span&gt; &lt;span class="s2"&gt;"$BROWSER"&lt;/span&gt;
&lt;span class="nb"&gt;command&lt;/span&gt; -v &lt;span class="s2"&gt;"$BROWSER"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then test the wrapper directly:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="s2"&gt;"$BROWSER"&lt;/span&gt; https://example.com
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Where to put the export depends on how the CLI is started:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;CLI context&lt;/th&gt;
&lt;th&gt;Where to set BROWSER&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Interactive Bash&lt;/td&gt;
&lt;td&gt;&lt;code&gt;~/.bashrc&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Zsh&lt;/td&gt;
&lt;td&gt;&lt;code&gt;~/.zshrc&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Login shell&lt;/td&gt;
&lt;td&gt;&lt;code&gt;~/.profile&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;systemd user service&lt;/td&gt;
&lt;td&gt;
&lt;code&gt;Environment=BROWSER=...&lt;/code&gt; in the unit&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;systemd user session&lt;/td&gt;
&lt;td&gt;&lt;code&gt;~/.config/environment.d/*.conf&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;If the CLI still reports no browser:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Check &lt;code&gt;printf '%s\n' "$BROWSER"&lt;/code&gt; in the same shell or service environment that launches the CLI.&lt;/li&gt;
&lt;li&gt;Make sure the CLI actually honors &lt;code&gt;BROWSER&lt;/code&gt;; some tools call &lt;code&gt;xdg-open&lt;/code&gt; or a platform opener directly.&lt;/li&gt;
&lt;li&gt;Restart the CLI after changing the variable. Many tools read &lt;code&gt;BROWSER&lt;/code&gt; only at startup.&lt;/li&gt;
&lt;li&gt;Remember that non-interactive shells may not read &lt;code&gt;~/.bashrc&lt;/code&gt;. Put the export in &lt;code&gt;~/.profile&lt;/code&gt; or the service environment.&lt;/li&gt;
&lt;li&gt;If the CLI runs under &lt;code&gt;sudo&lt;/code&gt;, check whether &lt;code&gt;BROWSER&lt;/code&gt; is preserved; &lt;code&gt;sudo&lt;/code&gt; often strips environment variables.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  What the Wrapper Cannot Fix
&lt;/h2&gt;

&lt;p&gt;The wrapper fixes a false negative, not every launch problem. Exit 1 is ambiguous: it means Explorer returned 1, not that a page rendered. If Explorer opens a folder instead of a browser, the wrapper still returns 0. &lt;a href="https://github.com/microsoft/WSL/issues/3832" rel="noopener noreferrer"&gt;A Microsoft WSL issue about &lt;code&gt;explorer.exe&lt;/code&gt; and URLs with query strings&lt;/a&gt; reports that some URLs with query arguments opened a generic File Explorer window instead of the browser on older WSL builds. If that happens, test with a simple &lt;code&gt;https://example.com&lt;/code&gt; first and consider &lt;code&gt;cmd.exe /c start&lt;/code&gt; or &lt;code&gt;wslview&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;The wrapper also does not:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Make a tool honor &lt;code&gt;BROWSER&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;Check which browser opened or whether the page loaded.&lt;/li&gt;
&lt;li&gt;Fix broken interop where Explorer returns 1 but nothing opens.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Those are separate problems. Use the wrapper only after you have confirmed that the browser actually opens and Explorer’s status is the only thing misleading the CLI. For an authentication flow, the reliable success signal is the redirect callback, not the browser launcher’s exit code.&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;&lt;code&gt;explorer.exe&lt;/code&gt; exit code 1 under WSL is usually a hand-off status, not a browser failure. When &lt;code&gt;BROWSER=explorer.exe&lt;/code&gt; opens the page but the CLI says it did not, the CLI is trusting a status that does not describe the browser. &lt;code&gt;set -e&lt;/code&gt; and short settle windows make that false negative worse.&lt;/p&gt;

&lt;p&gt;A status-aware wrapper fixes the mismatch without &lt;code&gt;|| true&lt;/code&gt;: it validates the URL, checks for &lt;code&gt;explorer.exe&lt;/code&gt;, accepts 0 and 1, and propagates 2, 126, 127, and other errors. Test it under &lt;code&gt;set -e&lt;/code&gt;, with an invalid target, with Explorer missing, and with a stub that returns an unexpected status. Export the wrapper by absolute path in the environment that actually launches the CLI, and remember that exit 1 still cannot prove a page rendered.&lt;/p&gt;

</description>
      <category>bash</category>
      <category>cli</category>
      <category>linux</category>
      <category>tutorial</category>
    </item>
  </channel>
</rss>
