Can not open browser in WSL when `server.open: true`
yunsii opened this issue · 10 comments
Describe the solution you'd like
Open browser in WSL when server.open: true
.
Of course it can not open the browser.
But there is no browser in WSL.
@FrankFang So it's a feature. When I use umi, it can open browser on Windows.
It uses the open
package which supports WSL, so yes it should be able to open the browser.
@theprimone do you have your Windows drives mounted somewhere other than /mnt/
? Vite currently uses open@7.4.0
which misses the fix to support other mount points
@theprimone yarn dev --open
works just fine for me on WSL, also BROWSER=chrome yarn dev --open
or BROWSER="C:\Path\To\Some\Browser.exe" yarn dev --open
.
However the open
package recently removed support for specifying the path to the .exe
as a posix path (/mnt/c/some/browser.exe
), so if your BROWSER
environment variable is set to that it won't work.
@jonaskuske It works with script BROWSER=chrome vite
after upgraded to vite@2.0.2
. Finally, I'm curious about what BROWSER
do?
@theprimone
BROWSER
is an environment variable that lets you specify which browser to use, you can either set it globally via your shell (e.g. in your ~/.bashrc
) or per-script by prepending BROWSER=x
to your command.
However if it isn't defined at all, open
should just use your default browser by running Start http://some.site
in PowerShell.
If yarn dev --open
(without prepending anything) is indeed not working for you, could you:
-
verify that running
Start https://www.google.com
in PowerShell works -
run
echo $BROWSER
in WSL and verify that the output it empty
It's empty when I run echo $BROWSER
in WSL.
And I also try BROWSER=firefox vite
, it will open firefox browser, I don't understand how it open browser correctly only by name like chrome
or firefox
😂
@theprimone
I don't understand how it open browser correctly only by name
Yep, strange indeed...
Should work fine even if BROWSER
is not set at all, as it just calls powershell.exe
with Start http://mysite.com
in that case 🤔