我正在尝试在我的Mac上安装MERN堆栈,但是,当我运行以下命令时:
sudo npm install -g mern-cli
我收到此错误消息:
request to https://registry.npmjs.org/mern-cli failed, reason: Hostname/IP doesn't 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"
我尝试了几件事,比如运行以下命令(解决了其他问题):
sudo npm config set registry https://registry.npmjs.org/
但是,这并没有解决问题。完全重新安装Node并没有解决问题。怎么解决这个?
编辑:完整的调试日志
0 info it worked if it ends with ok
1 verbose cli [ '/usr/local/bin/node',
1 verbose cli '/usr/local/bin/npm',
1 verbose cli 'install',
1 verbose cli '-g',
1 verbose cli 'mern-cli' ]
2 info using [email protected]
3 info using [email protected]
4 verbose npm-session f5dd10c6d19e4605
5 silly install loadCurrentTree
6 silly install readGlobalPackageData
7 silly fetchPackageMetaData error for mern-cli@latest request to https://registry.npmjs.org/mern-cli failed, reason: Hostname/IP doesn't 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"
8 verbose type system
9 verbose stack FetchError: request to https://registry.npmjs.org/mern-cli failed, reason: Hostname/IP doesn't 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"
9 verbose stack at ClientRequest.req.on.err (/usr/local/lib/node_modules/npm/node_modules/pacote/node_modules/make-fetch-happen/node_modules/node-fetch-npm/src/index.js:68:14)
9 verbose stack at emitOne (events.js:116:13)
9 verbose stack at ClientRequest.emit (events.js:211:7)
9 verbose stack at TLSSocket.socketErrorListener (_http_client.js:387:9)
9 verbose stack at emitOne (events.js:116:13)
9 verbose stack at TLSSocket.emit (events.js:211:7)
9 verbose stack at emitErrorNT (internal/streams/destroy.js:64:8)
9 verbose stack at _combinedTickCallback (internal/process/next_tick.js:138:11)
9 verbose stack at process._tickCallback (internal/process/next_tick.js:180:9)
10 verbose cwd /Users/Bjorn/Desktop/StoryOfAms
11 verbose Darwin 17.7.0
12 verbose argv "/usr/local/bin/node" "/usr/local/bin/npm" "install" "-g" "mern-cli"
13 verbose node v8.11.4
14 verbose npm v5.6.0
15 error request to https://registry.npmjs.org/mern-cli failed, reason: Hostname/IP doesn't 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"
16 verbose exit [ 1, true ]
正如许多其他答案所指出的那样,这似乎是一个全球问题,我也遇到了同样的问题。我按照https://status.npmjs.org/incidents/v22ffls5cd6h提供的说明确定了问题(如@muradm和其他人的建议)。
有关说明,您可以使用dig命令或使用谷歌DNS工具来检查www.npmjs.com的IP回答是什么。
结果是,在我的Hosts文件中包含以下行:
104.16.109.30 registry.npmjs.org
这解决了我的问题。请记住,这是一个临时修复,应该在周末后删除!祝好运!
- 编辑 -
此外,这假设您使用registry.npmjs.org作为您的NPM注册表端点(这是默认设置)。要检查,您可以运行:
npm config get registry
如果返回“https://registry.npmjs.com/”,您可以尝试添加到主机:
104.16.109.30 registry.npmjs.com
我刚刚测试过,工作正常!
P.S。:如果由于任何原因你不确定如何编辑主机文件,你可以在这里查看:https://www.howtogeek.com/howto/27350/beginner-geek-how-to-edit-your-hosts-file/
除了@jcemoller回答,对我来说:
npm config set strict-ssl false
然后它奏效了。
在问题完全解决后,应在一天左右的时间内恢复上述配置。
问题是全球性的。现在每个人都有同样的问题。
Hostname/IP doesn't 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"
添加这个可能会暂时解决,直到registry.npmjs.org稳定
rejectUnauthorized:false
我认为这是你的答案:
Node.js主机名/ IP与证书的altnames https://stackoverflow.com/a/16311147/6620340不匹配
你可以添加rejectUnauthorized:false
以避免安全检查。
对于到这里试图使用纱线的人来说;除了关于将registry.npmjs.com(或.org)放入hosts文件的说明之外,还要对yarn.npmjs.org执行相同的操作。
dig yarn.npmjs.org @1.1.1.1
例如,将其添加到/ etc / hosts:
104.16.23.35 yarn.npmjs.org
我现在完全添加到/ etc / hosts:
104.16.110.30 registry.npmjs.com
104.16.25.35 registry.npmjs.org
104.16.23.35 yarn.npmjs.org
请尝试以下:
sudo npm config set registry https://registry.npmjs.org/