本文最后更新于:2024年1月14日 晚上

安装 node.js 后可能出现 npm 安装包时报错unable to verify the first certificate的问题,本文记录解决方案。

错误复现

  • npm 命令安装包时失败报错
1
2
3
npm ERR! code UNABLE_TO_VERIFY_LEAF_SIGNATURE
npm ERR! errno UNABLE_TO_VERIFY_LEAF_SIGNATURE
npm ERR! request to https://registry.npm.taobao.org/vant failed, reason: unable to verify the first certificate

问题原因

1
As of February 27, 2014, npm no longer supports its self-signed certificates.

2014年2月27日,npm不再支持自签名证书。因为npm install走的是https协议,需要通过数字证书来保证的。

解决方案

  • 暂时取消ssl验证
1
npm config set strict-ssl false
  • 随后可以正常安装包,之后可以再开启
1
npm config set strict-ssl true
  • 如果还没有成功,npm源更换为国内镜像:
1
2
npm config set registry http://registry.cnpmjs.org/
npm config set registry http://registry.npm.taobao.org/

参考资料



文章链接:
https://www.zywvvd.com/notes/coding/node-js/nodejs-install-error/nodejs-install-error/


“觉得不错的话,给点打赏吧 ୧(๑•̀⌄•́๑)૭”

微信二维码

微信支付

支付宝二维码

支付宝支付

Node.js npm 安装包 unable to verify the first certificate 错误解决方案
https://www.zywvvd.com/notes/coding/node-js/nodejs-install-error/nodejs-install-error/
作者
Yiwei Zhang
发布于
2021年8月2日
许可协议