webpack配置webpack-dev-server後,啟動會報錯:Error: Cannot find module ‘webpack/bin/config-yargs‘
阿新 • • 發佈:2021-02-20
技術標籤:webpackdevServerwebpackjavascript
問題原因:webpack-cli的新版本對webpack-dev-server版本的不相容
解決方案:降低webpack-cli 版本為3.3.12
解除安裝webpack-cli
npm uni webpack-cli -D
安裝webpack-cli
npm i webpack-[email protected]3.3.12 -D
安裝webpack-dev-server
npm i webpack-dev-[email protected]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