Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to open local files in wsl #174

Open
captainjapeng opened this issue Mar 23, 2020 · 5 comments
Open

Unable to open local files in wsl #174

captainjapeng opened this issue Mar 23, 2020 · 5 comments

Comments

@captainjapeng
Copy link

captainjapeng commented Mar 23, 2020

I'm using this library from preview-email library and it fails to open the generated html file on WSL

I have found a partial solution but missing a code to differentiate between a Web URL or a filesystem path

	} else if (process.platform === 'win32' || isWsl) {

		command = 'cmd' + (isWsl ? '.exe' : '');
		cliArguments.push('/c', 'start', '""', '/b');
		target = target.replace(/&/g, '^&');

		if (options.wait) {
			cliArguments.push('/wait');
		}

		if (options.app) {
			if (isWsl && options.app.startsWith('/mnt/')) {
				const windowsPath = await wslToWindowsPath(options.app);
				options.app = windowsPath;
			}

			cliArguments.push(options.app);
		}

		// Convert local filepath to the one windows can understand
		// Needs to differentiate between web url and filepath
		if (isWsl) {
			target = await wslToWindowsPath(target);
		}

		if (appArguments.length > 0) {
			cliArguments.push(...appArguments);
		}
	} else {
@starptr
Copy link

starptr commented Apr 22, 2020

Having a similar problem here. I suspect it is due to this line:

if (isWsl && options.app.startsWith('/mnt/')) {

I played around with wslpath (which is executed by wslToWindowsPath) and it supports non-mounted paths. For example, /home/foo gets converted into \\wsl$\Ubuntu\home\foo. Unfortunately, simply changing the line to

if (isWsl) {

doesn't seem to fix it :(.

@sindresorhus
Copy link
Owner

A lot of changes have gone into WSL support. Is this still an issue?

@matej-marcisovsky
Copy link

Yes, this is still an issue. Latest version installed, WSL2 Ubuntu 22.04 and I can not open local HTML files. Opening URL (like https://google.com) works fine.

@thebnq
Copy link

thebnq commented Aug 23, 2023

preview-email was updated to take a urlTransformer. This fixes it for me:

urlTransform: (path: string) => `file://\\\\wsl.localhost/${process.env.WSL_DISTRO_NAME}${path}`

@romanlex
Copy link

romanlex commented Dec 7, 2023

What about this issue?
When run command from js api we get output
image

I think is wrong for wsl2 for example because it is Linux
when I'm try to run command with npx open I get run with linux binary xdg-open and all work perfectly

If I edit code https://github.com/sindresorhus/open/blob/main/index.js#L150 to
if (platform === 'darwin' || isWsl) {
all work perfectly

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants