今天在初始化一个项目的时候执行 npm install 遇到报错:

npm ERR! RequestError: Hostname/IP does not match certificate's altnames: Host: npm.taobao.org. is not in the cert's altnames: DNS:*.tbcdn.cn, DNS:*.taobao.com, DNS:*.alicdn.com, DNS:*.cmos.greencompute.org, DNS:cmos.greencompute.org, DNS:m.intl.taobao.com...

后面太长就省略了。

看起来是之前 taobao 镜像迁移,证书过期引起的问题。

npm config list 看了一下配置,发现了很多 npm.taobao.org 域名。看来要彻底清除一下了。

2024-04-16T08:42:46.png

  1. npm config ls | grep taobao 命令找出这些无效的 url:
chromedriver-cdnurl = "https://npm.taobao.org/mirrors/chromedriver" 
couchbase-binary-host-mirror = "https://npm.taobao.org/mirrors/couchbase/v{version}" 
debug-binary-host-mirror = "https://npm.taobao.org/mirrors/node-inspector" 
disturl = "https://npm.taobao.org/dist" 
electron-mirror = "https://npm.taobao.org/mirrors/electron/" 
flow-bin-binary-host-mirror = "https://npm.taobao.org/mirrors/flow/v" 
fse-binary-host-mirror = "https://npm.taobao.org/mirrors/fsevents" 
fuse-bindings-binary-host-mirror = "https://npm.taobao.org/mirrors/fuse-bindings/v{version}" 
git4win-mirror = "https://npm.taobao.org/mirrors/git-for-windows" 
gl-binary-host-mirror = "https://npm.taobao.org/mirrors/gl/v{version}" 
grpc-node-binary-host-mirror = "https://npm.taobao.org/mirrors" 
hackrf-binary-host-mirror = "https://npm.taobao.org/mirrors/hackrf/v{version}" 
leveldown-binary-host-mirror = "https://npm.taobao.org/mirrors/leveldown/v{version}" 
leveldown-hyper-binary-host-mirror = "https://npm.taobao.org/mirrors/leveldown-hyper/v{version}" 
mknod-binary-host-mirror = "https://npm.taobao.org/mirrors/mknod/v{version}" 
node-sqlite3-binary-host-mirror = "https://npm.taobao.org/mirrors" 
node-tk5-binary-host-mirror = "https://npm.taobao.org/mirrors/node-tk5/v{version}" 
nodegit-binary-host-mirror = "https://npm.taobao.org/mirrors/nodegit/v{version}/" 
operadriver-cdnurl = "https://npm.taobao.org/mirrors/operadriver" 
phantomjs-cdnurl = "https://npm.taobao.org/mirrors/phantomjs" 
profiler-binary-host-mirror = "https://npm.taobao.org/mirrors/node-inspector/" 
puppeteer-download-host = "https://npm.taobao.org/mirrors" 
python-mirror = "https://npm.taobao.org/mirrors/python" 
rabin-binary-host-mirror = "https://npm.taobao.org/mirrors/rabin/v{version}" 
sass-binary-site = "https://npm.taobao.org/mirrors/node-sass" 
sodium-prebuilt-binary-host-mirror = "https://npm.taobao.org/mirrors/sodium-prebuilt/v{version}" 
sqlite3-binary-site = "https://npm.taobao.org/mirrors/sqlite3" 
utf-8-validate-binary-host-mirror = "https://npm.taobao.org/mirrors/utf-8-validate/v{version}" 
utp-native-binary-host-mirror = "https://npm.taobao.org/mirrors/utp-native/v{version}" 
zmq-prebuilt-binary-host-mirror = "https://npm.taobao.org/mirrors/zmq-prebuilt/v{version}" 

共计 30 个。

重置的办法就是删除掉。

可以用 npm config delete <config_name> 的方法删除,不过前提是用 awk 命令提取一下参数,免得一条条复制。

  1. 使用 npm config ls | grep taobao | awk -F ' *= *' '{print $1}' 命令将配置名称全部提取出来
$ npm config ls | grep taobao | awk -F ' *= *' '{print $1}' 
chromedriver-cdnurl
couchbase-binary-host-mirror
debug-binary-host-mirror
disturl
electron-mirror
flow-bin-binary-host-mirror
fse-binary-host-mirror
fuse-bindings-binary-host-mirror
git4win-mirror
gl-binary-host-mirror
grpc-node-binary-host-mirror
hackrf-binary-host-mirror
leveldown-binary-host-mirror
leveldown-hyper-binary-host-mirror
mknod-binary-host-mirror
node-sqlite3-binary-host-mirror
node-tk5-binary-host-mirror
nodegit-binary-host-mirror
operadriver-cdnurl
phantomjs-cdnurl
profiler-binary-host-mirror
puppeteer-download-host
python-mirror
rabin-binary-host-mirror
sass-binary-site
sodium-prebuilt-binary-host-mirror
sqlite3-binary-site
utf-8-validate-binary-host-mirror
utp-native-binary-host-mirror
zmq-prebuilt-binary-host-mirror
  1. 复制到 sublime 或 vscode 中使用行编辑添加上前缀 npm config delete ,再执行。

2024-04-16T08:52:36.png

  1. 重新执行 npm install,顺利安装,问题解决。

标签: npm, taoabo