1.前提背景
因为很久之前就下载了vue,然后下载的是vue2.9.6版本,一直还没有开始使用vue,直到今年暑假前端开发要使用到vue,但是现在市面上的教程都是vue3版本的了,真的是经历了万千磨难,看了特别多的文章才终于解决了,特写一篇文章以祭奠我浪费的时间和为后续有人遇到这个问题提供一种解决方式。(ps:真的好多教程都是废话且没有用的啊……)
2.正式解决
1.很多博主推荐使用语句:
npm uninstall vue-cli -g
but!!!但是这个好像根本就没有用!!!反正我发现我卸载了之后,用vue -V还是原来的vue2.9.6版本的,而且尝试过无数遍都没有解决……
然后我又看了大量文章,正确的解决步骤如下:
1.先打开终端,输入:
where vue
你应该会见到如上的界面,然后你通过这个文件路径找到这两个文件并且删掉
为了保险,你可以输入:
npm uninstall vue-cli -g
然后查看版本号:
vue -V
终端输入提醒你没有这个指令就是卸载了。
2.输入:
npm config list
你应该会见到如上界面,找到 "user" config from C:\Users\86158\.npmrc 这一段话,通过这个文件路径找到这个文件并且删掉
3.在终端输入:
npm install -g @vue/cli
或
cnpm install -g @vue/cli
或
yarn global add @vue/cli
4.but!!!你会可能会遇到如下问题:
npm ERR! code ECONNRESET
npm ERR! syscall read
npm ERR! errno ECONNRESET
npm ERR! network request to https://registry.npmjs.org/@vue%2fcli failed, reason: read ECONNRESET
npm ERR! network This is a problem related to network connectivity.
npm ERR! network In most cases you are behind a proxy or have bad network settings.
npm ERR! network
npm ERR! network If you are behind a proxy, please make sure that the
npm ERR! network 'proxy' config is set properly. See: 'npm help config'
npm ERR! A complete log of this run can be found in: C:\Users\86158\AppData\Local\npm-cache\_logs\2024-07-17T09_53_55_300Z-debug-0.log
不用慌张!!
5.接下来输入:
npm cache clean --force
清除代理。输入:
npm config set registry https://registry.npm.taobao.org
6.but!!!你安装新版本vue的时候又可能遇到如下问题:
原因是淘宝镜像过期了。
npm ERR! code CERT_HAS_EXPIRED
npm ERR! errno CERT_HAS_EXPIRED
npm ERR! request to https://registry.npm.taobao.org/@vue%2fcli failed, reason: certificate has expired
npm ERR! A complete log of this run can be found in: C:\Users\86158\AppData\Local\npm-cache\_logs\2024-07-17T10_04_06_651Z-debug-0.log
再输入一遍:
npm cache clean --force
然后输入:
npm config set registry https://registry.npmmirror.com
7.最后再输入:
npm install -g @vue/cli
或
cnpm install -g @vue/cli
或
yarn global add @vue/cli
8.等待片刻,结束后再次输入:
vue -V
得到如上界面就证明成功了!!!
3.总结
经历了这么多终于解决了!!, 如果还有什么问题可以在评论区讨论或者私信我。