参考地址:https://www.cnblogs.com/zdz8207/p/vue-webpack-dev-server.html

     https://blog.csdn.net/qq_40557812/article/details/115220537?utm_medium=distribute.pc_relevant.none-task-blog-2~default~baidujs_title~default-1.no_search_link&spm=1001.2101.3001.4242

版本:

 

 

直接安装webpack-dev-server 对应的最新版本为@4.3.1,npm run dev时会报错:

node_modules\_webpack-dev-server@4.3.1@webpack-dev-server\lib\servers\WebsocketServer.js:10
  static heartbeatInterval = 1000;
                           ^

SyntaxError: Unexpected token =
    at new Script (vm.js:83:7)
    at NativeCompileCache._moduleCompile

  

网上搜索了,说是版本兼容问题,所以尝试降低webpack-dev-server版本为@2.9.1

(1)、npm uninstall webpack-dev-server
(2)、npm install webpack-dev-server@2.9.1
(3)、npm run dev

结果还是报错:(版本过低)

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

参考文档将版本升为@3.11.2,结果完美解决

package.json文件

  "scripts": {
    "dev": "webpack serve --progress --config ./webpack.config.js"
  },

  

posted on 2021-10-06 11:48  阿梅M  阅读(5624)  评论(0编辑  收藏  举报