question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Add default port as 8080 in options.js to match webpack-dev-server.js

See original GitHub issue
  • Operating System: Windows 10 x64
  • Node Version: v11.4.0
  • NPM Version: 6.4.1
  • webpack Version: 4.29.6
  • webpack-dev-server Version: 3.3.1
  • This is a bug
  • This is a modification request

Code

The minimal changes to webpack.config.js to introduce HMR are:

// webpack.config.js
// ....
devServer: {
    hot: true,
    port: 8080
}
// ...
plugins: [
    new HotModuleReplacementPlugin(),
    // other plugins...
]

Expected Behavior

The port option should default to 8080 (just like the server does).

Actual Behavior

The port option does not have a default, which results in the generated code trying to contact webpack-dev-server at the default port (for URLs) of 80.

Relevant webpack-dev-server code

In bin/webpack-dev-server.js

const DEFAULT_PORT = 8080;

In bin/options.js (missing a default key)

  port: {
    describe: 'The port',
    group: CONNECTION_GROUP,
  },

For Bugs; How can we reproduce the behavior?

Simply remove the port option above from a simple webpack-dev-server example project. There will be console errors on the loaded page, and if you check the generated bundle code, you’ll find that it tries to contact webpack-dev-server at http://localhost instead of http://localhost:8080

For Features; What is the motivation and/or use-case for the feature?

Having less required options makes webpack much more approachable to beginners looking to “just make it work”.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:5
  • Comments:29 (14 by maintainers)

github_iconTop GitHub Comments

2reactions
alsotangcommented, Oct 16, 2019

In v3.8.2, when using with program style, you also need to specify the port in options

	new WebpackDevServer(compiler, {
		port: 8080, // do not ignore this
	}).listen(8080, 'localhost', function(err) {
		console.log("[webpack-dev-server]", "http://localhost:8080/webpack-dev-server/index.html");
	});
2reactions
alexander-akaitcommented, Apr 17, 2019

I think it is bug:

  1. we need findPort (https://github.com/webpack/webpack-dev-server/blob/master/bin/webpack-dev-server.js#L242) before run compilation https://github.com/webpack/webpack-dev-server/blob/master/bin/webpack-dev-server.js#L145 so you always have port
  2. Add test on cli and node api usage
Read more comments on GitHub >

github_iconTop Results From Across the Web

How do I change webpack dev server's default port from 8080 ...
You can use the devServer.port option in the webpack config. devServer: { port: 9000 }. Alternatively you can use the --port CLI option...
Read more >
DevServer - webpack
webpack is a module bundler. Its main purpose is to bundle JavaScript files for usage in a browser, yet it is also capable...
Read more >
webpack-dev-server - npm
Start using webpack-dev-server in your project by running `npm i ... In the directory where your webpack.config.js is, run:.
Read more >
Setting up the Webpack Dev Server - Three.js Tutorials
Dev Server has been initialized using an options object that does not match the API schema. - options has an unknown property 'contentBase'....
Read more >
Static website, multiple html pages, using Webpack + example ...
Requirements at hand; Choosing task runner/bundler; Development server; More HTML pages; Adding CSS; Use latest Javascript language features ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found