open: Open Unable to Connect to localhost on Windows WSL (v. 7.0.0)

For some reason I cannot open to my localhost port with the current version of the package (7.0.0). Attempting to do so yields the following error:

Windows cannot find '\http://localhost:3000\'. Make sure you typed the name correctly, and then try again.

Here is my JavaScript code:

import express from 'express';
import path from 'path';
import open from 'open';

const app = express();
const port = process.env.PORT || 3000;

app.get(['/'], function(req, res) {
  res.sendFile(path.join(__dirname, '../public/index.html'));
});

app.listen(port, function(err) {
  if (err) {
    console.error(err);
  } else {
    console.info(`App listening on port ${port}`);
    open('http://localhost:' + port);
  }
});

Note that everything works correctly on version 6.4.0, and I can open to my localhost just fine with that. It’s only on 7.0.0 that I’m seeing this issue.

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Reactions: 15
  • Comments: 19 (6 by maintainers)

Commits related to this issue

Most upvoted comments

Yeah, I’ve arrived at the same conclusion. The sad part is I’ve not been able to find any documentation that even begins to explain why. I guess we could just check if we’re in WSL (as some other caveats already do).

If I have to make a guess I will think it is because node thinks it is in Unix, therefore ignore the windowsVerbatimArguments option.

windowsVerbatimArguments <boolean> No quoting or escaping of arguments is done on Windows. Ignored on Unix. Default: false. source

@herberttn i created very simple repro case. Just clone and run node index.js. I used WSL1 and node 10. Untitled If you install open@6 it will starts workimg

Just a heads up: this should be fixed now via #166 and #168.

Did some more testing. So far it looks like it’s only happening when you run via WSL.

✔️ Regular cmd/bash on Windows ✔️ Mac ❌ WSL on Windows

Yeah, I’ve arrived at the same conclusion. The sad part is I’ve not been able to find any documentation that even begins to explain why. I guess we could just check if we’re in WSL (as some other caveats already do).

@sindresorhus would you be comfortable with it?

@FKobus The final PR (#168) landed in release v7.0.2. (#166 itself landed in v7.0.1)

@herberttn my bad. I tried to reproduce it again, couldn’t reproduce it on Windows. Only on WSL for me