webpack-cli: [DEP_WEBPACK_WATCH_WITHOUT_CALLBACK] error when using `--watch` flag

Describe the bug

PR with the configuration https://github.com/javascript-obfuscator/javascript-obfuscator/pull/776

After upgrade from webpack@4 to webpack@5 and webpack-cli@3 to webpack-cli@4.0.0 I got the following error:

[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.

This error happens only when using --watch flag:

webpack --config ./webpack/webpack.node.config.js --mode development --watch

Full error trace:

(node:62890) [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/sanex/WebstormProjects/javascript-obfuscator/node_modules/webpack/lib/webpack.js:145:5)
    at f (/Users/sanex/WebstormProjects/javascript-obfuscator/node_modules/webpack/lib/index.js:35:15)
    at Compiler.createCompiler (/Users/sanex/WebstormProjects/javascript-obfuscator/node_modules/webpack-cli/lib/utils/Compiler.js:129:35)
    at WebpackCLI.run (/Users/sanex/WebstormProjects/javascript-obfuscator/node_modules/webpack-cli/lib/webpack-cli.js:220:32)
    at async runCLI (/Users/sanex/WebstormProjects/javascript-obfuscator/node_modules/webpack-cli/lib/bootstrap.js:74:24)

Expected behavior

No error.

About this issue

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

Most upvoted comments

Fixed in webpack-cli@4.2.0, if somebody faced with the problem again, please open a new issue with reproducible test repo, because we tests most of cases 😄

I will fix it 👍

Release will be today

@snitin315 No, will be fixed in the near future, the next PR

I did update to "webpack": "^5.3.2" and the error still appears

[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.

I get the same error, but I think it’s worth mentioning that the watch mode does actually work. Yes, it throws that warning at the start, but it still bundles and still watches for changes correctly.

Same problem for me when trying to upgrade to webpack@5.1.3 and webpack-cli@4.0.0

Some problems on webpack side with new API, we are working on it, so I will do release with other fixes, but it will be fixed tomorrow with patch release

Running latest webpack 5.22 and webpack-cli 4.5 - No errors !

Just note, this is unnecessary using --watch and watch: true together, just remove watch: true from the config

Fixed in webpack-cli@4.2.0, if somebody faced with the problem again, please open a new issue with reproducible test repo, because we tests most of cases 😄

I still have this problem!

“webpack”: “^5.10.3”, “webpack-cli”: “^4.2.0”, “webpack-dev-server”: “^3.11.0”

node: v14.15.0 npm: 6.14.8 mac: 10.14.6

github

√ Webpack
  Compiled successfully in 1.55s

[webpack-cli] Compilationdevelopment starting...
(node:10048) [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.
(Use `node --trace-deprecation ...` to show where the warning was created)

You need update webpack-cli to the latest stable version

“webpack”: “^5.61.0” getting same warning when I set the watch property value to true in the config file and running this code:

let entries = [{
    watch : true
}];
let compiler = webpack(entries);
compiler.watch({
    aggregateTimeout: 1000,
    poll: undefined
},(err, stats) => {})

if I set to false the watch property value in config so the warning is gone. Anyway, this warning I guess is harmless so it’s not big deal.

Had a quick look and removing watch: true from config will not help as --watch is still propagated to options

https://github.com/webpack/webpack/blob/master/lib/webpack.js#L140

Looks like we would need to refactor how the webpack-cli handles complier ( have some wip already but would require https://github.com/webpack/webpack/pull/11784 )

I have this with this project https://github.com/styled-components/vscode-styled-components/blob/master/package.json and we don’t have watch: true set. Looks like 4.1.0 is out so we will try that

@gimmi why need to spam it? I’ve always tried to figure it out, but I can’t, can you explain it to me?

We have two problems here:

  • watch without callback
  • we don’t respect the watch option from config