首页 前端知识 npm设置淘宝镜像

npm设置淘宝镜像

2024-04-23 21:04:55 前端知识 前端哥 597 305 我要收藏

1、设置npm为淘宝镜像

npm config set registry https://registry.npm.taobao.org/
//这将设置npm的registry配置为淘宝镜像。

2、或者设置cnpm为淘宝镜像

npm install -g cnpm --registry=https://registry.npm.taobao.org

如果您觉得每次都输入命令比较麻烦,也可以将这个命令添加到npm配置文件中。

3、验证配置是否生效

npm config get registry
or
cnpm config get registry

如果终端返回的是淘宝镜像的地址,那么配置已经生效了。

4、切换为官网的镜像

需要注意的是,如果您以后需要切换回npm官方的镜像,可以使用以下命令:

npm config set registry https://registry.npmjs.org/

5、解决安装其他插件报错

npm ERR! code CERT_HAS_EXPIRED
npm ERR! errno CERT_HAS_EXPIRED
npm ERR! request to https://registry.npm.taobao.org/which/download/which-2.0.2.tgz?cache=0&sync_timestamp=1577793984045&other_urls=https%3A%2F%2Fregistry.npm.taobao.org%2Fwhich%2Fdownload%2Fwhich-2.0.2.tgz failed, reason: certificate has expired

npm ERR! A complete log of this run can be found in:
npm ERR!     C:\Users\DS\AppData\Local\npm-cache\_logs\2024-03-08T03_29_52_165Z-debug-0.log

方案一:更新或修复npm的SSL证书

npm cache clean --force

方案二:在npm配置中禁用严格的SSL验证

npm cache clean --force
npm config set strict-ssl false
转载请注明出处或者链接地址:https://www.qianduange.cn//article/5892.html
评论
发布的文章
大家推荐的文章
会员中心 联系我 留言建议 回顶部
复制成功!