npm安装失败(安装MERN堆栈)

时间:2018-09-01 09:53:27

标签: node.js npm terminal mern

但是,当我运行以下命令时,我正在尝试在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 npm@5.6.0
3 info using node@v8.11.4
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 ]

6 个答案:

答案 0 :(得分:3)

正如许多其他答案所指出的那样,这似乎是一个全球性的问题,我也遇到了同样的问题。我确实按照https://status.npmjs.org/incidents/v22ffls5cd6h上的说明通过(如@muradm等人的建议)解决了这个问题。

其中的说明是,您可以使用dig命令或使用Google 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/

答案 1 :(得分:1)

除了@jcemoller回答之外,对我来说:

然后它起作用了。

在问题完全解决之后,以上配置应在一天左右的时间内恢复。

答案 2 :(得分:0)

我认为这是您的答案:

Node.js主机名/ IP与证书的替代名称不匹配 https://stackoverflow.com/a/16311147/6620340

您可以添加rejectUnauthorized:false以避免进行安全检查。

答案 3 :(得分:0)

问题是全球性的。现在每个人都可能遇到相同的问题。

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

答案 4 :(得分:0)

对于任何来这里尝试使用纱线的人;除了有关将registry.npmjs.com(或.org)放入主机文件的说明之外,对yarn.npmjs.org的操作也相同

dig yarn.npmjs.org @1.1.1.1

例如,将其添加到/ etc / hosts:

104.16.23.35 yarn.npmjs.org

我现在对/ ets / hosts的完整添加是:

104.16.110.30 registry.npmjs.com
104.16.25.35 registry.npmjs.org
104.16.23.35 yarn.npmjs.org

答案 5 :(得分:-1)

请尝试以下操作:

sudo npm config set registry https://registry.npmjs.org/