webpack-dev-server: `webpack-dev-server`v4 cannot start with 'localhost'

  • Operating System: MacOS
  • Node Version: 14.15.0
  • NPM Version: 6.14.9
  • webpack Version: 5.10.3
  • webpack-dev-server Version: 4.0.0-beta.0
  • Browser: Google Chrome
  • This is a bug
  • This is a modification request

Code

// webpack.config.js
module.exports = {
    ...,
    devServer: {
        host: 'localhost'
    }
}

Expected Behavior

The browser opens and starts with http://localhost:8080

Actual Behavior

The browser starts with http://127.0.0.1:8080 and logs this:

[webpack-dev-server] Project is running at http://127.0.0.1:8080/

For Bugs; How can we reproduce the behavior?

Cause this code server.address().address always return 127.0.0.1 There is the code permalink: https://github.com/webpack/webpack-dev-server/blob/910133d0a2383823504b3a0c2fd21b5a86e733a4/lib/utils/createDomain.js#L14

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Comments: 16 (7 by maintainers)

Most upvoted comments

Yes, we need to do release, a lot of issue, try to do new release on this week

Some PRs should be merged, I am working on it

Should be fixed in master, I’ll do it from tomorrow and do new beta release

📝@alexander-akait I do not use beta-0 because i’m both hacking around and writing types, and I wanted to take into account latest api changes.

🔶 Instally from github directly just do not work (at least with yarn), because some files need a build step after cloning the repo (I get an error related to some ../../client module not being found) That’s part of the reason why I was asking this.

🟢In case it helps I ended-up cloning the repo, tweaking things around, building it, creating an npm tarball with npm pack, copying the archive in my project, then installing it via some {..., "webpack-dev-server": "file:./forks/webpack-dev-server-4.0.0.tgz", ...}. It was the best compromise I found to avoid polluting git history, and ensuring everyone on my team use the same version.