Nodejs npm 服务器的证书好像出问题了
Nodejs npm 服务器的证书好像出问题了
我 npm install 的时候,一直报:
Unexpected warning for https://registry.npmjs.org/: Miscellaneous Warning ERR_TLS_CERT_ALTNAME_INVALID: request to https://registry.npmjs.org/react-scripts failed, reason: Hostname/IP does not match certificate's altnames: Host: registry.npmjs.org. is not in the cert's altnames: DNS:a.sni.fastly.net, DNS:a.sni.global-ssl.fastly.net
搜了下 SO,发现不少人都在问,比如这贴:NPM not installing package. Hostname/IP doesn't match certificate's altnames:
底下有人回复说,浏览器访问 https://registry.npmjs.org/http-server 也会报证书问题。我试了下,真的是……
是的,CDN 证书错了。
嗯,现在修复了~
有没有想过,哪天 NPM 之类的不再维护了,无法 npm install, 你写的 Node 程序也都没用了?
针对您提到的Node.js npm服务器证书出问题的情况,这通常表现为在尝试使用npm安装或更新包时遇到CERT_HAS_EXPIRED
错误。以下是一些专业的解决步骤,希望能帮助您解决问题:
-
清除npm缓存:
npm cache clean --force
-
检查并更新npm镜像源: 有时npm的默认镜像源可能会出现证书问题,您可以尝试切换到其他镜像源,例如淘宝镜像:
npm config set registry https://registry.npm.taobao.org/
-
禁用SSL验证(不推荐,但可作为临时解决方案): 禁用SSL验证可以解决证书问题,但会降低安全性。您可以通过设置npm的
strict-ssl
选项为false
来实现:npm config set strict-ssl false
-
更新npm和Node.js: 旧版本的npm可能因证书过期而无法正常工作,尝试更新npm到最新版本:
npm install -g npm[@latest](/user/latest)
-
检查系统时间: 确保您的系统时间设置正确,因为不正确的系统时间可能会导致SSL证书认证失败。
如果以上步骤仍未能解决问题,建议查看npm官方文档或在开发社区中寻求帮助。