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

[DEP_WEBPACK_WATCH_WITHOUT_CALLBACK] error when using webpack serve with --watch flag #2370

Closed
benediktarnold opened this issue Jan 21, 2021 · 7 comments · Fixed by #2375
Closed
Labels

Comments

@benediktarnold
Copy link

Describe the bug

When running webpack serve with --watch the deprecation warning DEP_WEBPACK_WATCH_WITHOUT_CALLBACK shows up. Initially I thought it's just the same as #1918 but it's a different code path.

What is the current behavior?

When running node with --trace-deprecation this is the full deprecation stack:

10% building(node:54129) [DEP_WEBPACK_WATCH_WITHOUT_CALLBACK] DeprecationWarning: A 'callback' argument need to be provided to the 'webpack(options, callback)' function when the 'watch' option is set. There is no way to handle the 'watch' option without a callback.
    at webpack (/Users/ben/dev/playground/webpack-deprecation-warning/node_modules/webpack/lib/webpack.js:143:5)
    at f (/Users/ben/dev/playground/webpack-deprecation-warning/node_modules/webpack/lib/index.js:37:15)
    at WebpackCLI.createCompiler (/Users/ben/dev/playground/webpack-deprecation-warning/node_modules/webpack-cli/lib/webpack-cli.js:1337:24)
    at async Command.<anonymous> (/Users/ben/dev/playground/webpack-deprecation-warning/node_modules/@webpack-cli/serve/lib/index.js:65:30)
    at async Promise.all (index 1)
    at async Command.<anonymous> (/Users/ben/dev/playground/webpack-deprecation-warning/node_modules/webpack-cli/lib/webpack-cli.js:824:13)

To Reproduce

Steps to reproduce the behavior:

  1. checkout https://github.com/benediktarnold/webpack-deprecation-warning
  2. run npm install && npm start

Expected behavior

No deprecation warning

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

System:
  OS: macOS 11.1
  CPU: (12) x64 Intel(R) Core(TM) i7-9750H CPU @ 2.60GHz
  Memory: 74.99 MB / 32.00 GB
Binaries:
  Node: 15.5.0 - /usr/local/bin/node
  Yarn: 1.22.10 - /usr/local/bin/yarn
  npm: 7.3.0 - /usr/local/bin/npm
Browsers:
  Chrome: 87.0.4280.141
  Firefox: 84.0.1
  Safari: 14.0.2
Packages:
  webpack: ^5.16.0 => 5.16.0
  webpack-cli: ^4.4.0 => 4.4.0
  webpack-dev-server: ^3.11.2 => 3.11.2
Global Packages:
  webpack: 5.11.1

Additional context

I think the root cause is in

const compiler = await cli.createCompiler(webpackOptions);
where no callback is provided.

@alexander-akait
Copy link
Member

You should not use --watch and serve together, it doesn't have sense, message is some misleading, but just remove it from your command

@benediktarnold
Copy link
Author

That is indeed misleading since webpack serve --help mentions --watch as a possible option:

% webpack serve --help                                                                                                                                                                                                                                                                                                                  
Usage: webpack serve|s [options]

Run the webpack dev server.

Options:
  -c, --config <value...>     Provide path to a webpack configuration file e.g. ./webpack.config.js.
  --config-name <value...>    Name of the configuration to use.
  -m, --merge                 Merge two or more configurations using 'webpack-merge'.
  --env <value...>            Environment passed to the configuration when it is a function.
  --progress [value]          Print compilation progress during build.
  -j, --json [value]          Prints result as JSON or store it in a file.
  -d, --devtool <value>       Determine source maps to use.
  --no-devtool                Do not generate source maps.
  --entry <value...>          The entry point(s) of your application e.g. ./src/main.js.
  --mode <value>              Defines the mode to pass to webpack.
  --name <value>              Name of the configuration. Used when loading multiple configurations.
  -o, --output-path <value>   Output location of the file generated by webpack e.g. ./dist/.
  --stats [value]             It instructs webpack on how to treat the stats e.g. verbose.
  --no-stats                  Disable stats output.
  -t, --target <value...>     Sets the build target e.g. node.
  -w, --watch                 Watch for files changes.
  --no-watch                  Do not watch for file changes.

Could you please explain why it doesn't make sense to use serve with --watch? Thanks in advance!
Besides that, the help mentions --no-watch as well. Adding that option to the call has no effect at all and changed files are still compiled immediately.

@snitin315
Copy link
Member

Could you please explain why it doesn't make sense to use serve with --watch? Thanks in advance!

serve already watches for changes.

@snitin315
Copy link
Member

Maybe be we can add a warning here -

Do not use serve with --watch. serve already watches for changes.

@alexander-akait
Copy link
Member

alexander-akait commented Jan 21, 2021

Could you please explain why it doesn't make sense to use serve with --watch? Thanks in advance!

It just has no effect.

Maybe be we can add a warning here -

Yes, warning will be great, and let's hide watch and --no-watch from help for serve and watch command

@snitin315
Copy link
Member

I will send a PR

@benediktarnold
Copy link
Author

Thanks for your help and your immediate PR! 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants