webpack配置webpack-dev-server后,启动会报错:Error: Cannot find module ‘webpack/bin/config-yargs‘

webpack配置webpack-dev-server后,启动会报错:Error: Cannot find module ‘webpack/bin/config-yargs‘_第1张图片webpack配置webpack-dev-server后,启动会报错:Error: Cannot find module ‘webpack/bin/config-yargs‘_第2张图片

问题原因:webpack-cli的新版本对webpack-dev-server版本的不兼容
解决方案:降低webpack-cli 版本为3.3.12

卸载webpack-cli
npm uni webpack-cli -D  
安装webpack-cli
npm i webpack-cli@3.3.12 -D 

安装webpack-dev-server
npm i webpack-dev-server@3.11.0 -D

package.json 配置

"start": "webpack-dev-server",

webpack.config.js 配置

 devServer: {
    contentBase: "./dist",//设置服务器访问的根目录
    host: "localhost",//访问的ip地址
    port: 8080,//端口
    open: true//自动打开页面
  },

然后重新启动 npm start

你可能感兴趣的:(脚手架,webpack,javascript)