在centos中使用 npm install 命令报错如下:

09:13:56 npm WARN network SKIPPING OPTIONAL DEPENDENCY: request to https://registry.npm.taobao.org/nan failed, reason: getaddrinfo ENOTFOUND registry.npm.taobao.org registry.npm.taobao.org:443
09:13:56 npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@1.2.4 (node_modules/fsevents):
09:13:56 npm WARN network SKIPPING OPTIONAL DEPENDENCY: request to https://registry.npm.taobao.org/fsevents failed, reason: getaddrinfo ENOTFOUND registry.npm.taobao.org registry.npm.taobao.org:443

于是经过长达半个小时的搜索也没有找到答案,最后猜测是不是服务器网络或者host有问题

试了下 ping www.baidu.com

[root@localhost ~]# ping www.baidu.com
ping: www.baidu.com: Name or service not known

发现找不到百度的服务器,证明了这台服务器的host存在问题,于是定位到 /etc/resolv.conf 文件打开查看

[root@localhost ~]# vi /etc/resolv.conf

# Generated by NetworkManager
nameserver fd20:25f7:e485::1

添加下DNS到 resolv.conf 文件中

nameserver 114.114.114.114

保存文件,再次 ping www.baidu.com

[root@localhost ~]# ping www.baidu.com
PING www.a.shifen.com (14.215.177.38) 56(84) bytes of data.
64 bytes from 14.215.177.38 (14.215.177.38): icmp_seq=1 ttl=51 time=36.1 ms

至此问题解决

最后修改:2020 年 02 月 20 日 10 : 06 AM