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 --watch flag #1918

Closed
sanex3339 opened this issue Oct 11, 2020 · 43 comments
Closed

[DEP_WEBPACK_WATCH_WITHOUT_CALLBACK] error when using --watch flag #1918

sanex3339 opened this issue Oct 11, 2020 · 43 comments

Comments

@sanex3339
Copy link

Describe the bug

PR with the configuration
javascript-obfuscator/javascript-obfuscator#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.

@sanex3339 sanex3339 added the Bug label Oct 11, 2020
@alexander-akait
Copy link
Member

@webpack/cli-team high priority

@photonstorm
Copy link

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.

@raduchiriac
Copy link

raduchiriac commented Oct 12, 2020

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

@snitin315
Copy link
Member

I will fix it 👍

@alexander-akait
Copy link
Member

We have two problems here:

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

@snitin315
Copy link
Member

@evilebottnawi fixed with #1931 ?

@alexander-akait
Copy link
Member

alexander-akait commented Oct 13, 2020

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

@alexander-akait
Copy link
Member

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

@gimmi
Copy link

gimmi commented Oct 18, 2020

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

@alexander-akait
Copy link
Member

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

@alexander-akait
Copy link
Member

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

@jakebailey
Copy link

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.

@alexander-akait
Copy link
Member

@jakebailey Can you provide link on example of problem, removing watch: true should help

@jakebailey
Copy link

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.

@alexander-akait
Copy link
Member

@jakebailey Very strange, should be no problems

@jasonwilliams
Copy link

jasonwilliams commented Oct 21, 2020

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

@tkurki
Copy link

tkurki commented Oct 21, 2020

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.

@chadleong
Copy link

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

@piecyk
Copy link
Contributor

piecyk commented Oct 22, 2020

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 webpack/webpack#11784 )

@alexander-akait
Copy link
Member

@piecyk Can you clarify?

@piecyk
Copy link
Contributor

piecyk commented Oct 22, 2020

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(...)

@alexander-akait
Copy link
Member

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

@thisVioletHydra
Copy link

√ 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)

@nestorvanz
Copy link

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.

@jdelStrother
Copy link

jdelStrother commented Nov 4, 2020

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 2cb0c0e

@alexander-akait
Copy link
Member

Release will be today

@alexander-akait
Copy link
Member

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 😄

@xccjk
Copy link

xccjk commented Dec 16, 2020

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

@pedro-w
Copy link

pedro-w commented Dec 16, 2020

@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

@xccjk
Copy link

xccjk commented Dec 16, 2020

@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

  • node v14.15.0
  • npm 6.14.8
  • mac 10.14.6

@lebadapetru
Copy link

"webpack": "^5.12", and this still occurs

@alexander-akait
Copy link
Member

You need update webpack-cli to the latest stable version

@lebadapetru
Copy link

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

@chadleong
Copy link

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

@PeterBowater
Copy link

Once I had updated webpack-cli it was all good :)

@xeroxstar
Copy link

xeroxstar commented Dec 10, 2021

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

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

Successfully merging a pull request may close this issue.