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

Posted vieber

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Error: Cannot find module ‘webpack/bin/config-yargs‘相关的知识,希望对你有一定的参考价值。

报错信息

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

报错原因

将webpack从3升级到5报这个错误

解决过程

直接搜索,需要将启动语法从原来的

  "dev": "webpack-dev-server --inline --progress --config build/webpack.dev.conf.js",

改成

 "dev": "webpack server --config build/webpack.dev.conf.js --progress",

改完之后发现还是报错,但是提示需要安装webpack-cli,然后就安装下

npm install -D webpack-cli

装了之后启动,然后报新的错误

[webpack-cli] You need to install 'webpack-dev-server' for running 'webpack serve'.
Error: Cannot find module 'webpack-dev-server/bin/cli-flags'
Require stack:

看说明需要安装

webpack-dev-server

尝试装下试试,但是安装又报版本的错误

npm ERR! code ERESOLVE
npm ERR! ERESOLVE unable to resolve dependency tree
npm ERR!
npm ERR! While resolving: notepad@1.0.0
npm ERR! Found: webpack@5.74.0
npm ERR! node_modules/webpack
npm ERR!   webpack@"^5.74.0" from the root project
npm ERR!
npm ERR! Could not resolve dependency:
npm ERR! peer webpack@"^2.2.0 || ^3.0.0" from webpack-dev-server@2.11.5
npm ERR! node_modules/webpack-dev-server
npm ERR!   dev webpack-dev-server@"^2.11.5" from the root project
npm ERR!
npm ERR! Fix the upstream dependency conflict, or retry
npm ERR! this command with --force, or --legacy-peer-deps
npm ERR! to accept an incorrect (and potentially broken) dependency resolution.

说我目前webpack5没有这个webpack-dev-server这个事webpack2或者3才有的东西,那说明现在启动方式还是不对,不能用这个webpack-dev-serevr启动,仔细发现我本地的package.json里面的不对,版本还是老的,我需要卸载重新安装才行。

然后启动还是报错

Failed to load '/Users/sufubo/code/project/webproject/build/webpack.dev.conf.js' config
[webpack-cli] TypeError: webpack.NamedModulesPlugin is not a constructor

看起来就是webpack语法的问题了,我尝试修改下。

以上是关于Error: Cannot find module ‘webpack/bin/config-yargs‘的主要内容,如果未能解决你的问题,请参考以下文章

Error: Cannot find module ‘express‘

Error: Cannot find module ‘express‘

Error: Cannot find module ‘dotenv‘解决方法

Error: Cannot find module ‘dotenv‘解决方法

Error: Cannot find module ‘dotenv‘的解决方法

Error: Cannot find module ‘dotenv‘的解决方法