shayloyuki

勇气

 

npm run serve 报错 Cannot read property 'split' of null 并且接口500

问题

项目本地启动报错如下,且接口返回500。

image

解决

定位到 requires-port 源码:
image

打印结果显示 protocal 确实为 null

image

image

要想解决此问题,则需要判断 process.env.VUE_APP_URL 的值是否为null。

image

经过仔细排查发现,报错原因是 .env 文件中,地址后有一个空格。去掉空格即可正常启动项目

image

参考链接

  1. vue 解决跨域时报错 Cannot read property ‘split‘ of null

  2. 揭秘Vue项目中的env文件空格陷阱:如何避免潜在bug,提升开发效率?

posted on 2025-12-01 17:24  shayloyuki  阅读(1)  评论(0)    收藏  举报

导航