我使用的是nvm和最新的稳定Node (16)
$ nvm ls
-> v16.2.0
npm最近执行TLS 1.1和一个模糊的博客。
根据另一篇博文,npm@latest
应该是npm 7。然而,对我来说:
npm install -g npm@latest
npm WARN npm npm does not support Node.js v16.2.0
npm WARN npm You should probably upgrade to a newer version of node as we
npm WARN npm can't make any promises that npm will work with this version.
npm WARN npm Supported releases of Node.js are the latest release of 6, 8, 9, 10, 11, 12, 13.
npm WARN npm You can find the latest version at https://nodejs.org/
npm WARN registry Unexpected warning for https://registry.npmjs.org/: Miscellaneous Warning UNABLE_TO_GET_ISSUER_CERT_LOCALLY: request to https://registry.npmjs.org/npm failed, reason: unable to get local issuer certificate
npm WARN registry Using stale data from https://registry.npmjs.org/ due to a request error during revalidation.
+ npm@6.13.0
updated 1 package in 9.573s
您可以看到@latest
for me解析为npm 6.13.0,此警告的关键部分显示为:
https://registry.npmjs.org/:其他警告unable_to_get_issuer_cert_local:请求https://registry.npmjs.org/npm失败,原因:无法获得本地颁发者证书在重新验证期间,由于请求错误,npm警告registry使用来自https://registry.npmjs.org/的陈旧数据。
我曾经把我的注册表设置为使用http,如:
$ npm config get registry
http://registry.npmjs.org/
所以我试着取消设置,显然它会自动设置为https
(这很好):
$ npm config delete registry
$ npm config get registry
https://registry.npmjs.org/
但是我得到了相同的"陈旧的数据"。npm install -g npm@latest
运行时出现UNABLE_TO_GET_ISSUER_CERT_LOCALLY
警告。npm install -g npm
也有同样的警告。我是不能升级npm了
我没有使用VPN或任何代理。我该如何解决这个问题?
首先我尝试用nvm重新安装节点,它将我升级到nvm 8,但未能解决问题:
nvm reinstall-packages 16
我注意到我的~/.npmrc
中有一行:
ca[]=
由于某种原因,我把npm配置为没有根证书来验证SSL。删除这一行修复了我的问题。