NPM 淘宝镜像域名证书过期

更新日期: 2024-09-23 阅读次数: 1329 字数: 262 分类: Javascript

在通过 NPM 安装一个微信小程序官方组件时,报错。

NPM 安装报错

> npm install @miniprogram-component-plus/index-list

npm ERR! code CERT_HAS_EXPIRED
npm ERR! errno CERT_HAS_EXPIRED
npm ERR! request to https://registry.npm.taobao.org/@miniprogram-component-plus%2findex-list failed, reason: certificate has expired

npm ERR! A complete log of this run can be found in:
npm ERR!     /home/xxx/.npm/_logs/2024-07-02T03_15_02_726Z-debug-0.log

查看 NPM 配置

> npm config list

; "user" config from /home/xxx/.npmrc

registry = "https://registry.npm.taobao.org/"

; node bin location = /usr/local/bin/node

设置新的淘宝 NPM 镜像

原来的镜像 registry.npm.taobao.org 不再维护,所以域名证书过期也不更新了。 需要切换为新的淘宝镜像:

> npm config set registry https://registry.npmmirror.com

确认是否已生效

> npm config list

registry = "https://registry.npmmirror.com/"

然后再次使用 npm install 就可以正常工作了。

yarn 的设置方法

如果使用的是 yarn,对应的修改方法为:

yarn config set registry https://registry.npmmirror.com

确认修改成功:

yarn config get registry

测试没有问题,再次使用 yarn add ... 命令,例如:

yarn add react-datepicker

就可以正常安装依赖了。

但是,比较奇怪的是,tyarn 这样修改,并不生效。

微信关注我哦 👍

大象工具微信公众号

我是来自山东烟台的一名开发者,有敢兴趣的话题,或者软件开发需求,欢迎加微信 zhongwei 聊聊, 查看更多联系方式