sindresorhus/opn

Do you want to work on this issue?

You can request for a bounty in order to promote it!

Unable to open local files in wsl #174

captainjapeng posted onGitHub

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 {

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 :(.

posted by starptr about 5 years ago

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

posted by sindresorhus about 4 years ago

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.

posted by matej-marcisovsky about 2 years ago

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}`
posted by thebnq over 1 year ago

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

posted by romanlex over 1 year ago

Fund this Issue

$0.00
Funded
Only logged in users can fund an issue

Pull requests