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

Current package.json file

"devDependencies": {
    "webpack": "^ 5.37.0"."webpack-cli": "^ 4.1.12"."webpack-dev-server": "^ 3.11.2"
}
Copy the code

Find the problem:

Search for error messages in issues in webPack’s Github project to find the problem:

Error: Cannot find module ‘webpack-cli/bin/config-yargs’ #1948

If you upgrade webpack to 5. *, and webpack cli to 4. *, an error will be reported:

Error: Cannot find module ‘webpack-cli/bin/config-yargs’ Temporary solution: Back off webpack cli to version 3. * for example:

“Webpack – cli” : “^ 3.3.12”

Solve a problem:

  1. Uninstall the current Webpack – CLI

npm uninstall webpack-cli

  1. Install webPack – CLI 3.* version

npm install webpack-cli@3 -D

Modified package.json file

"devDependencies": {
    "webpack": "^ 5.37.0"."webpack-cli": "^" 3.3.12."webpack-dev-server": "^ 3.11.2"
}
Copy the code

Run NPM run dev again to compile successfully.

Conclusion:

It is recommended that you check the issues of the corresponding project for any problems ~