【bug修复】 —— webpack5 webpack-dev-server 版本兼容
参考地址:https://www.cnblogs.com/zdz8207/p/vue-webpack-dev-server.html
版本:
直接安装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
越是迷茫、浮躁的时候,保持冷静和耐心,尤为重要