1

I'm trying to install the MERN stack on my Mac, however, when I run the following command:

sudo npm install -g mern-cli

I get this error message:

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"

I tried several things, like running the following command (which solved the problem for others):

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

However, this doesn't solve the problem. Also reinstalling Node completely didn't solve the problem. How to solve this?

EDIT: Full debug log

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 ]
Bjorn B.
  • 506
  • 3
  • 10

6 Answers6

3

As many other answers are pointing out, this seems to be a global issue, I'm also experiencing the same. I did fix the problem by (like suggested by @muradm and others) following the instructions available at https://status.npmjs.org/incidents/v22ffls5cd6h.

The instructions there are that you check yourself what is the IP answering to www.npmjs.com by using the dig command, or using google DNS tool.

The result of that, was to include in my Hosts file the following line:

104.16.109.30   registry.npmjs.org

This solved the issue for me. Remember this is a temporary fix and should be removed after the weekend! Good luck!

-- edit --

Also, this is assuming that you are using registry.npmjs.org as your NPM registry endpoint (which is the default setting). To check that, you can run:

npm config get registry

If that returns "https://registry.npmjs.com/" for example, you can try adding to your hosts:

104.16.109.30   registry.npmjs.com

Which I just tested and works fine!

P.S.: If for any reason you are unsure how to edit hosts file, you can check here: https://www.howtogeek.com/howto/27350/beginner-geek-how-to-edit-your-hosts-file/

Paulo Muñoz
  • 281
  • 2
  • 4
1

In addition to @jcemoller answer, for me:

Then it worked.

Above configurations should be reverted in a day or so, after the problem is completely resolved.

muradm
  • 1,973
  • 19
  • 30
0

I thinks here is your answer:

Node.js Hostname/IP doesn't match certificate's altnames https://stackoverflow.com/a/16311147/6620340

you can add rejectUnauthorized:false to avoid that security check.

Zoe
  • 27,060
  • 21
  • 118
  • 148
Gerardo Perrucci
  • 704
  • 7
  • 13
0

The problem is global. Now everyone probably having same issue.

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"

Adding this may solve temporary until the registry.npmjs.org is stable rejectUnauthorized:false

Zoe
  • 27,060
  • 21
  • 118
  • 148
micksatana
  • 183
  • 1
  • 6
0

For anyone arriving here trying to use yarn; In addition to the instructions about putting the registry.npmjs.com ( or .org) in your hosts file, also do the same for yarn.npmjs.org

dig yarn.npmjs.org @1.1.1.1

And for example add this to /etc/hosts:

104.16.23.35 yarn.npmjs.org

My complete addition to /ets/hosts is now:

104.16.110.30 registry.npmjs.com
104.16.25.35 registry.npmjs.org
104.16.23.35 yarn.npmjs.org
Thijs Koerselman
  • 21,680
  • 22
  • 74
  • 108
-1

Please try below:

sudo npm config set registry https://registry.npmjs.org/
Zoe
  • 27,060
  • 21
  • 118
  • 148