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 [email protected] 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.
@webpack/cli-team high priority
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.
Indeed, webpack v5 does not watch anymore if I remove --watch and do webpack --config webpack.config.js
I use this config:
{
mode: "development",
watch: true,
devtool: "inline-cheap-source-map",
watchOptions: {
ignored: ["node_modules/**"],
},
entry: {
main: ["core-js/stable", "./src/js/index.js"],
theme: "./src/scss/th.scss",
},
}
Solution: With my config above the only way to go is adding --watch which I'd prefer not to
I will fix it 👍
We have two problems here:
watch option from config@evilebottnawi fixed with #1931 ?
@snitin315 No, will be fixed in the near future, the next PR
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
Same problem for me when trying to upgrade to [email protected] and [email protected]
@gimmi why need to spam it? I've always tried to figure it out, but I can't, can you explain it to me?
Just note, this is unnecessary using --watch and watch: true together, just remove watch: true from the config
I hit this with the latest versions of everything and I don't have watch: true set, so I don't think this config option being duplicated is the whole story.
@jakebailey Can you provide link on example of problem, removing watch: true should help
I haven't yet pushed the changes to my project to grab 4.1.0 quite yet (holding back dep updates for a release, but will likely do it soon), but the config that it'd be is here: https://github.com/microsoft/pyright/blob/master/packages/vscode-pyright/webpack.config.js
Where the task just runs webpack --mode development --watch --progress.
@jakebailey Very strange, should be no problems
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
I just created https://gist.github.com/tkurki/5627039d52ca0248648ed383294f57f6 and with that I get the DeprecationWarning running npx webpack --watch. Install gave me 4.1.0.
I am running webpack 5.1.3 and webpack-cli 4.1.0 with
"dev": "webpack --mode development --watch ./src/frontend/src/index.js -o ./src/frontend/static/frontend/"
Still get the same [DEP_WEBPACK_WATCH_WITHOUT_CALLBACK] error
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 )
@piecyk Can you clarify?
Can you clarify?
@evilebottnawi on which part ?
webpack-cli creates compiler via https://github.com/webpack/webpack-cli/blob/master/packages/webpack-cli/lib/webpack-cli.js#L219
Using --watch will set {watch: true} on this.compilerConfiguration that we pass as option to webpack. On webpack side we create compiler without callback that's why it logs a warning at https://github.com/webpack/webpack/blob/master/lib/webpack.js#L140
Looks like there is no option to opt out from warning just to pass a callback when calling webpack(...)
Using --watch will set {watch: true} on this.compilerConfiguration that we pass as option to webpack.
We should fix it
Also we can remove watch: true from config when you run webpack --watch with warnings message
We should fix it
Yes i agree. But should the fix be to remove watch from options what are passed to webpack? Maybe options.watch used in some internal logic. Imho we should fix it without patching options.
Also we can remove watch: true from config when you run webpack --watch with warnings message
Don't follow this, but having watch: true in config and running with --watch should not change anything.
Yes i agree. But should the fix be to remove watch from options what are passed to webpack? Maybe options.watch used in some internal logic. Imho we should fix it without patching options.
Don't follow this, but having watch: true in config and running with --watch should not change anything.
No, having watch: true in config means to start watching at once, but we need more logic here, compiler.watch() === { watch: true }
@evilebottnawi I was thinking about something like this https://github.com/webpack/webpack-cli/compare/master...piecyk:fix-watch
Almost all test pass, only still need to check analyze-flag.test.js, and one in cache-flags.test.js.
Also there is error code change, as webpack is wrapping with try catch and not propagating errors https://github.com/webpack/webpack/blob/master/lib/webpack.js#L135 there is no easy way to choose between error code 1 vs 2, decided for simplicity to go with 1
@piecyk bad fix, with breaking changes
But idea is good, I will look at this in near future
with breaking changes
Do you mean the exit code change ?
But idea is good, I will look at this in near future
👍
Also if we would push a plugin into compile like for example WebpackCLILogPlugin
we could use webpack logger for logging. With some additional fine tuning the logger could work perfectly.

@piecyk Yes, can you send a PR (don't use fork) and I will finish your work
√ 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)
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 think we're still waiting on a new release ( > 4.1.0 ) for this. If I test against the master branch it seems to work fine.
(You can use the master branch with yarn add --dev https://gitpkg.now.sh/webpack/webpack-cli/packages/webpack-cli)
EDIT: ~which is weird because allegedly 4.1.0 was the one that fixed watch mode. I'm still trying to narrow down exactly what fixed it...~ The deprecation warning was fixed in https://github.com/webpack/webpack-cli/commit/2cb0c0e383670949ce31231edbfda514f47c3dfc
Release will be today
Fixed in [email protected], if somebody faced with the problem again, please open a new issue with reproducible test repo, because we tests most of cases :smile:
Fixed in
[email protected], 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
@xccjk I did a fresh checkout of your https://github.com/xccjk/webpack-demo1 and didn't see this problem.
I did see a "DEP_WEBPACK_COMPILATION_ASSETS" but this comes from html-webpack-plugin
@xccjk I did a fresh checkout of your https://github.com/xccjk/webpack-demo1 and didn't see this problem.
I did see a "DEP_WEBPACK_COMPILATION_ASSETS" but this comes from
html-webpack-plugin
- node v14.15.1
- npm 6.14.8
- Windows 10 x64
Thank you very much for your reply, but after removing html-webpack-plugin, I still have the same problem. I updated the github address after removing redundant packages
"webpack": "^5.12", and this still occurs
You need update webpack-cli to the latest stable version
i'm not actually using pure webpack but webpack encore which uses webpack-cli 4, i see that 4.5 is the latest version but i guess i'll have to wait for webpack encore to upgrade it
Running latest webpack 5.22 and webpack-cli 4.5 - No errors !
Most helpful comment
Fixed in
[email protected], if somebody faced with the problem again, please open a new issue with reproducible test repo, because we tests most of cases :smile: