今天配置vue.config.js, 配置后,启动项目,报了一个错

 INFO  Starting development server...
 ERROR  TypeError: Cannot read properties of undefined (reading 'upgrade')
TypeError: Cannot read properties of undefined (reading 'upgrade')
    at Server.<anonymous> (/Users/lhf/cguardian/gdmall-blue-pc/node_modules/webpack-dev-server/lib/Server.js:1843:26)
    at Array.forEach (<anonymous>)
    at Server.initialize (/Users/lhf/cguardian/gdmall-blue-pc/node_modules/webpack-dev-server/lib/Server.js:1838:29)
    at Server.start (/Users/lhf/cguardian/gdmall-blue-pc/node_modules/webpack-dev-server/lib/Server.js:3208:16)
    at processTicksAndRejections (node:internal/process/task_queues:96:5)

这个错误报出来,一开始让我难以理解。对比之前的vue.config.js中的配置,完全没有差别。
经过查询资料,stackoverflow 给我了解决问题的答案: I guess your devServer.proxy.target is empty! You could set this configuration

经过验证,确实是devServer.proxy配置中,target没有值。

就是我在配置代理的时候,target是通过环境变量获取的。但是环境变量属性值配置错了,导致报了这个错误。

参考资料:
https://stackoverflow.com/questions/55348996/cannot-read-property-upgrade-of-undefined-when-starting-vue-application

Logo

华为开发者空间,是为全球开发者打造的专属开发空间,汇聚了华为优质开发资源及工具,致力于让每一位开发者拥有一台云主机,基于华为根生态开发、创新。

更多推荐