Skip to content

Depecrated way of passing compiler and options does not work if options is not defined #3659

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

Closed
1 of 2 tasks
johanlajili opened this issue Aug 17, 2021 · 7 comments
Closed
1 of 2 tasks

Comments

@johanlajili
Copy link

johanlajili commented Aug 17, 2021

  • This is a bug
  • This is a modification request

Code

In Server.js, the signature of the constructor is "(options={}, compiler)".
For reasons I have not looked into, there is a temporary code (signaled by a TODO), that reverses those two if options.hooks is true. I'm guessing essentially making it work with (options, compiler) as well as (compiler, options).
But compiler does not have a default value, unlike options. So if you call

new WebpackDevServer(compiler)

without options, options will be undefined, which throws an error when calling validate.

new WebpackDevServer(compiler, {})

works.

This used to work in our pipeline and stopped working suddenly, not sure what caused it, probably an update somewhere.

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

  System:
    OS: macOS Mojave 10.14.6
    CPU: (8) x64 Intel(R) Core(TM) i5-8279U CPU @ 2.40GHz
    Memory: 1.72 GB / 16.00 GB
  Binaries:
    Node: 14.16.1 - /usr/local/bin/node
    Yarn: 1.22.10 - /usr/local/bin/yarn
    npm: 6.14.12 - /usr/local/bin/npm
  Browsers:
    Brave Browser: 81.1.8.95
    Chrome: 92.0.4515.159
    Chrome Canary: 95.0.4609.3
    Firefox Developer Edition: 92.0
    Safari: 14.1.2
  Packages:
    clean-webpack-plugin: ^4.0.0-alpha.0 => 4.0.0-alpha.0
    copy-webpack-plugin: ^5.1.2 => 5.1.2
    dotenv-webpack: ^7.0.2 => 7.0.3
    html-webpack-plugin: ^5.3.1 => 5.3.2
    webpack: ^5.35.1 => 5.50.0
    webpack-bundle-analyzer: ^4.4.1 => 4.4.2
    webpack-cli: ^4.7.0 => 4.8.0
    webpack-dev-server: ^4.0.0-beta.3 => 4.0.0-rc.0
    webpack-modules: ^1.0.0 => 1.0.0

Expected Behavior

I can call WebpackDevServer with only a compiler without passing options

Actual Behavior

If you just call new WebpackDevServer(compiler) it will throw an error, even though

new WebpackDevServer(compiler, {})

and

new WebpackDevServer(undefined, compiler)

work

For Bugs; How can we reproduce the behavior?

see above snippet.

@alexander-akait
Copy link
Member

Please use new WebpackDevServer({}, compiler)

@alexander-akait
Copy link
Member

You should always pass options to constructor, if you have not options, please use undefined or {} object

@johanlajili johanlajili changed the title Options does not have a default value if "compiler.hooks" is true Depecrated way of passing compiler and options does not work if options is not defined Aug 17, 2021
@johanlajili
Copy link
Author

Even if it's deprecated you shouldn't just break it until it's actually removed, this is a breaking change for some people.

@alexander-akait
Copy link
Member

Do you mean new WebpackDevServer(compiler) should work?

@alexander-akait
Copy link
Member

We are in beta, it is not stable and never be stable

@johanlajili
Copy link
Author

Well, if you're bothering with a support for the legacy order of arguments, it should work with the legacy order of arguments. Deprecated means "will stop working in a future version" not "well maybe it works maybe it doesn't, who knows".
Anyway it's your project you do what you want, we fixed our side, I'm just saying you could fix countless headaches from other people with a simple ?? {} in your temporary argument switcheroo code

@alexander-akait
Copy link
Member

#3660

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

No branches or pull requests

2 participants