webpack / webpack-dev-server

Serves a webpack app. Updates the browser on changes. Documentation https://webpack.js.org/configuration/dev-server/.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Error: Cannot find module 'webpack-cli/bin/config-yargs'

yilmazbingo opened this issue · comments

  • Operating System: kali-2020

  • Node Version: v10.21.0

  • NPM Version: 6.14.7

  • webpack Version: ^5.0.0

  • webpack-dev-server Version:^3.11.0"

  • This is a bug

  • This is a modification request

Code

Expected Behavior

webpack-dev-server should compile

Actual Behavior

Error: Cannot find module 'webpack-cli/bin/config-yargs'

webpack-dev-server is dependent on the webpack-cli. looks like it has been updated 13 hours ago to version 4.0.0 so its folder structure has changes. here is the current folder structure:
webpack-cli

this is the older folder structure i just created a few days ago:
Screen Shot 2020-10-11 at 4 15 54 AM

Yes - webpack-dev-server does not work with webpack-cli v4

Same there. But when will it get fixed?

Can you try webpack serve ?

@snitin315 What is the difference between webpack-dev-server and webpack serve? Does it mean I do not need webpack-dev-server when I use webpack v5?

Yes webpack-cli v4 comes with out of box support of @webpack-cli/serve which means you can use webpack serve to invoke the webpack-dev-server.

We need to add try/catch to our cli when we require module from webpack-cli and output a warning to use webpack serve to run webpack dev server

Able to reproduce the bug in Windows.

Can you provide an example of how we replace the use of devServer in our webpack config file with serve?

Please update webpack-cli to v4 and use webpack serve to run webpack-dev-server

How are environment options passed to webpack serve when exporting a function in the webpack config? With webpack-dev-server, I passed environment variables:

webpack-dev-server --env.mode development

Passing the same argument to webpack serve errors:

[webpack-cli] Unknown argument: --env.mode
[webpack-cli] Unknown argument: development

I'm not seeing how to pass anything other than booleans to webpack serve, but I want to pass strings:

webpack serve --env mode

I would hope since it seems it is understood what is needed for webpack-dev-server to work with webpack 5, the authors would put a fix in ASAP to resolve this issue. I too am trying webpack serve, and am not able to get it to work. In the future, when suggesting a change like this, it would be extremely beneficial to provide a simple example of how it should work. As it is, it seems this requires knowledge or figuring out how serve works which is different than how webpack-dev-server works.

Please update webpack-cli to v4 and use webpack serve to run webpack-dev-server

I also had to reinstall webpack dev server (v3.11.0) to make it work.

"dev": "webpack server --env development"

"webpack": "^5.0.0",
"webpack-cli": "^4.0.0",
"webpack-dev-server": "^3.11.0",

ERROR in main
Module not found: Error: Can't resolve 'server' in '*********'

webpack 5.0.0 compiled with 1 error in 521 ms

what should I do?

@wanliyunyan Should be webpack serve not server:

"dev": "webpack serve --mode development --env development"

@wanliyunyan Should be webpack serve not server:

"dev": "webpack serve --mode development --env development"

thank you,.............

The migration guide says we should be using webpack-dev-server instead of serve:

``
serve ↦ serve is removed in favor of DevServer


[https://webpack.js.org/migrate/5/]{https://webpack.js.org/migrate/5/)

Furthermore HMR no longer works when I switch to 'serve'. The browser console logo shows [HMR] Waiting for update signal from WDS... but nothing happens. Going back to Webpack 4

@YahzeeSkellington

That serve/devServer mentioned in migration is a configure defined in webpack configuration, not the one used in CLI.

Regarding the HMR, you might have the similar issue as #2758 if you have browserslist in your project.

@YahzeeSkellington as @chenxsan said, I removed "browsersList" from package.json and hot reload work well.

webpack serve did not serve well :) Ran into more errors. Finally reverted to
"webpack": "^4.41.3",
"webpack-cli": "^3.3.10",
"webpack-dev-server": "^3.9.0"

Please stop spam, we known about the problem and we provide solution above, we need additional try/catch in our bin and provide friendly error