webpack-cli: error: option '--open ' argument missing

As per the request here https://github.com/webpack/webpack.js.org/pull/4099#issuecomment-718825131.

Describe the bug

webpack serve --open throws an error:

error: option '--open <value>' argument missing

What is the current behavior?

To Reproduce

Steps to reproduce the behavior:

  1. git clone https://github.com/chenxsan/webpack-demo
  2. git checkout 8ffd9d229ce344fb4b595e4045aee7b074be16cc
  3. npm install
  4. npm start

Expected behavior

Screenshots

Please paste the results of webpack-cli info here, and mention other relevant information

Additional context

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Reactions: 24
  • Comments: 32 (10 by maintainers)

Most upvoted comments

I had the same issue, but adding the open: true in the devServer block of webpack.config.js, seems to work for me.

  devServer: {
    contentBase: path.join(__dirname, 'dist'),
    port: 9000,
    open: true
  }

I was following the tutorial from the official website.

This --open argument bug happened before and there are some stack overflow questions and GitHub issues of the same bug.

If you just like me, trying to learn Webpack and don’t care, providing the url allows you to continue: webpack serve --open Chrome.exe

Providing a url like @zero41120 said didn’t work for me. But, webpack serve --open 'Google Chrome' works. Replace Google Chrome with your browser name.

@cannandev @snitin315 Yes. Looks like the --open just opens whatever you provide, for example webpack serve --open notepad.exe

I think it worked for me because that I’m on windows environment, and it knows that http uses my default browser. I will update my original comment.

remove --open from "start": "webpack serve --open" and add that into your webpack.config.js:

...
devServer: {
    port: 3000,
    host: '127.0.0.1',
    open: true
  },
...

in this case, that opens your default browser

Had the same problem, fixed it by just using webpack serve without --open or a browser value. I’d then have to open the browser and go to the localhost server http://localhost:8080/

Según lo nuevo de webpack en su documentación, a la hora de configurar el webpack-dev-server hay que usar así la estructura del objeto

devServer:{ contentBase: ‘./dist’, compress: true, // este es el importante, puesto que al compilar, resulta con warning ya que le pide comprimir el archivo open: true, port: 5000 },

En realidad si, lo puedes lograr así. Solo que cambio la forma explicita como estaba definida la sintaxis.

"dev-server": "webpack serve --open chrome"

This works for me, on a windows 10 machine with NodeJs 15 and webpack 5

webpack serve --open chrome will fix the issue

Yes, string functionality ( webpack --open 'browser-name') works fine.