【bug修复】 —— webpack5 webpack-dev-server 版本兼容

参考地址: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时会报错:

[webpack-cli] C:\Users\Administrator\Desktop\webpack5学习demo\7-devServer\node_modules\webpack-dev-server\lib\servers\WebsocketServer.js:10
  static heartbeatInterval = 1000;
                           ^

SyntaxError: Unexpected token =
    at Module._compile (internal/modules/cjs/loader.js:723:23)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:789:10)
    at Module.load (internal/modules/cjs/loader.js:653:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:593:12)
    at Function.Module._load (internal/modules/cjs/loader.js:585:3)
    at Module.require (internal/modules/cjs/loader.js:692:17)
    at require (internal/modules/cjs/helpers.js:25:18)
    at Server.getServerTransport (C:\Users\Administrator\Desktop\webpack5学习demo\7-devServer\node_modules\webpack-dev-server\lib\Server.js:1663:28)
    at Server.createWebSocketServer (C:\Users\Administrator\Desktop\webpack5学习demo\7-devServer\node_modules\webpack-dev-server\lib\Server.js:2443:57)
    at Server.start (C:\Users\Administrator\Desktop\webpack5学习demo\7-devServer\node_modules\webpack-dev-server\lib\Server.js:3229:12)

网上搜索了,说是版本兼容问题,参考文档将版本升为@3.11.2,结果完美解决

npm uninstall webpack-dev-server
npm install webpack-dev-server@3.11.2

npx webpack serve

posted @ 2022-03-03 16:05  柳洁琼Elena  阅读(689)  评论(0编辑  收藏  举报