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

webpack-dev-serverv4 cannot start with 'localhost' #2934

Closed
1 of 2 tasks
jerryOnlyZRJ opened this issue Dec 16, 2020 · 16 comments · Fixed by #3102
Closed
1 of 2 tasks

webpack-dev-serverv4 cannot start with 'localhost' #2934

jerryOnlyZRJ opened this issue Dec 16, 2020 · 16 comments · Fixed by #3102

Comments

@jerryOnlyZRJ
Copy link

  • 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:

hostname = server.address().address;

@alexander-akait
Copy link
Member

Yes, because we resolve localhost to real API

@jerryOnlyZRJ
Copy link
Author

jerryOnlyZRJ commented Dec 17, 2020

Yes, because we resolve localhost to real API

@alexander-akait But there is a case that some old projects had been set cookies with localhost domain for e2e tests or other usages. If the dev server starts with real IP, those cookies will not work cause of cross-origin. How can we compatible with them more smoothly?

@alexander-akait
Copy link
Member

It is just output [webpack-dev-server] Project is running at http://127.0.0.1:8080/, server starts on localhost and you can open localhost in your browser

@jerryOnlyZRJ
Copy link
Author

jerryOnlyZRJ commented Dec 17, 2020

It is just output [webpack-dev-server] Project is running at http://127.0.0.1:8080/, server starts on localhost and you can open localhost in your browser

@alexander-akait But most projects will set devServer.open = true, then the devServer will start http://127.0.0.1:8080/ in the browser. For the user, it will be confused because I set devServer.host to be localhost, but the browser opens the 127.0.0.1

runOpen(uri, options, logger);

@alexander-akait
Copy link
Member

Solved in master, you can try

@jerryOnlyZRJ
Copy link
Author

Solved in master, you can try

@alexander-akait The master branch seems cannot work with webpack v5. I use a symbolic link and use webpack-dev-server like this:

const WebpackDevServer = require('webpack-dev-server/lib/Server');

// ...

const server = new WebpackDevServer(compiler, devServerOptions)

server.listen(8080, 'localhost, () => {
  console.log('Starting server on http://localhost:8080');
});

and it throws an Error:

TypeError: The 'compilation' argument must be an instance of Compilation

@jerryOnlyZRJ jerryOnlyZRJ changed the title webpack-dev-serverv4 cannot be start with 'localhost' webpack-dev-serverv4 cannot start with 'localhost' Dec 21, 2020
@akphi
Copy link

akphi commented Dec 23, 2020

@alexander-akait I think you have fixed tons of these issues on master, do you think we can try release beta.1? If not, what are the current blockers if any; maybe we should create a mega-thread for all of these, what do you think? Thank you so much!

@alexander-akait
Copy link
Member

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

@jerryOnlyZRJ
Copy link
Author

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

@alexander-akait Is there a new version for webpack5?

@rvion
Copy link

rvion commented Jan 22, 2021

@alexander-akait could you share what is the recommanded way to test with master until the release is done ?

@alexander-akait
Copy link
Member

alexander-akait commented Jan 22, 2021

@rvion why do not use beta-0, anyway if you need master - use this https://stackoverflow.com/questions/17509669/how-to-install-an-npm-package-from-github-directly (install from github), run npm i inside node_modules/webpack-dev-server and you have bundled master

@rvion
Copy link

rvion commented Jan 24, 2021

📝@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.

@akphi
Copy link

akphi commented Jan 24, 2021

@alexander-akait sorry, is there anything blocking the release of beta-1?

@alexander-akait
Copy link
Member

Some PRs should be merged, I am working on it

@rvion
Copy link

rvion commented Mar 5, 2021

@alexander-akait thanks ! is there any update on this ?

@alexander-akait
Copy link
Member

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

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

Successfully merging a pull request may close this issue.

4 participants