解决报错Cannot find module 'webpack-cli/bin/config-yargs'

责编:menVScode 2018-03-09 13:19 阅读(5965)

当执行webpack-dev-server命令的时候就报以下错误:

$ webpack-dev-server

The CLI moved into a separate package: webpack-cli.
Please install 'webpack-cli' in addition to webpack itself to use the CLI.
-> When using npm: npm install webpack-cli -D
-> When using yarn: yarn add webpack-cli -D
module.js:471
    throw err;
    ^

Error: Cannot find module 'webpack-cli/bin/config-yargs'
    at Function.Module._resolveFilename (module.js:469:15)
    at Function.Module._load (module.js:417:25)
    at Module.require (module.js:497:17)
    at require (internal/module.js:20:19)
    at Object.<anonymous> (C:\Users\wangzhencan\Desktop\self\multi_page_packing\
    at Module._compile (module.js:570:32)
    at Object.Module._extensions..js (module.js:579:10)
    at Module.load (module.js:487:32)
    at tryModuleLoad (module.js:446:12)
    at Function.Module._load (module.js:438:3)

当时我的 webpack 和 webpack-dev-server版本如下:

"webpack": "^4.1.1",
"webpack-dev-server": "^3.1.1"

后来查了下可能是因为Webpack与webpack-dev-server版本不兼容导致。

通过以下命令进行卸载和重装:

卸载: npm uninstall webpack -g
重装: npm install webpackr@3.10.1 -g

最后 webpack 和 webpack-dev-server版本如下执行正常不报错:

"webpack": "^3.10.0",
"webpack-dev-server": "^2.9.7"
标签: webpack
前端交流群: MVC前端网(menvscode.com)-qq交流群:551903636

邮箱快速注册

忘记密码