vue-cli 3.0 执行 vue-cli-service serve,启动报错

执行后输出:

$ vue-cli-service serve
 INFO  Starting development server...
 10% building 2/2 modules 0 active ERROR  TypeError: Cannot read property 'upgrade' of undefined
TypeError: Cannot read property 'upgrade' of undefined
    at Server.<anonymous> (D:\www\ENESYS-new-edition\EnesysReporting-frontend\node_modules\webpack-dev-server\lib\Server.js:142:47)
    at Array.forEach (<anonymous>)
    at new Server (D:\www\ENESYS-new-edition\EnesysReporting-frontend\node_modules\webpack-dev-server\lib\Server.js:141:27)
    at serve (D:\www\ENESYS-new-edition\EnesysReporting-frontend\node_modules\@vue\cli-service\lib\commands\serve.js:137:20)
    at <anonymous>
    at process._tickCallback (internal/process/next_tick.js:188:7)
    at Function.Module.runMain (module.js:695:11)
    at startup (bootstrap_node.js:191:16)
    at bootstrap_node.js:612:3
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

错误定位至 node_modules\webpack-dev-server\lib\Server.js 文件的142行:

this.websocketProxies.forEach(function(wsProxy) {
  this.listeningApp.on('upgrade', wsProxy.upgrade);
}, this);

删除node_modules目录重新拉取不能解决,希望曾经遇到或了解该问题的朋友能指点下,谢谢各位!

11.06 补充:
我已经通过下列方式避开这一问题,但是显然治标不治本:

this.websocketProxies.forEach(function(wsProxy) {
  if (!wsProxy) return;
  this.listeningApp.on('upgrade', wsProxy.upgrade);
}, this);
阅读 17.7k
2 个回答

代理地址为空导致的

devServer.proxy 配置异常, 二分法排查并重新配置即可 。

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题