6
votes

When I run $ npm run dev ("dev": "webpack-dev-server") it opens localhost:8080/undefined instead of localhost:8080 or at least localhost:8080/index.html

webpack-config.js devServer part:

devServer: {

    contentBase: path.join(__dirname, 'dist'),

    compress: true,

    stats: "errors-only",

    hot: true,

    open: true

If I delete the /undefined part of the URL it works properly even the hot module replacement so it's not a big problem; just want to know why is that happening.

Edit: Im on MacOS

Edit2: Console info when npm run dev:

Project is running at http://localhost:8080/ webpack output is served from / Content not from webpack is served from /Users/cozarkd/folders/dist webpack: wait until bundle finished: /undefined webpack: Compiled successfully.

Ty

1
What is output.publicPath? - robertklep
Im not sure what do you need but maybe this helps: (edited the main post because don't know how to write on comment properly) - Diego de Sousa
I can't reproduce this with Webpack v3 (for me, the server opens http://localhost:8080/webpack-dev-server/). Which version of Webpack are you using? - robertklep
Webpack 2.5.1 webpack-dev-server 2.4.5 Should I try to update? I remember that this same project worked fine on my last computer (still does, just the undefined thing) When I ran npm run dev I got localhost:8080 and index.html opened. I still can do that but only manually deleting /undefined from the url - Diego de Sousa
Ouch sorry, never mind, I was using an old version of webpack-dev-server :-( I just updated to 2.5.0 and it's showing the same error. Looks to be a bug: github.com/webpack/webpack-dev-server/issues/960 - robertklep

1 Answers

14
votes

This seems to be caused by a bug: https://github.com/webpack/webpack-dev-server/issues/960

A quick workaround is offered (here):

devServer: {
  contentBase: path.join(__dirname, 'dist'),
  compress: true,
  stats: "errors-only",
  hot: true,
  open: true,
  openPage: '' // <-- this
}