Socket.io unable to verify the first certificate

2019-06-09 02:25发布

I've got node.js installed and running on pc. When I make a pakage.json as shown below, then in that folder run cmd

npm install socket.io 

or

npm install 

it gives the error

unable to verify the first certificate

How can I fix this?

package.json

{
  "name": "app",
  "version": "0.0.1",
  "description": "app",
  "dependencies": {
  "socket.io": "latest"
},
  "author": "shadryck"
}

NOTE: I am completely new to node.js and socket.io. I'm just trying to get started with it somehow.

NOTE: if for some reason you're going to downvote this at least explain why. I do have done my research and was unable to find an answer anywhere.

UPDATE: fixed it by reinstalling node.js and restarting pc after not having restarted it for a very long time.

UPDATE: installed python, but now its whining for even more errors. screenie

2条回答
ゆ 、 Hurt°
2楼-- · 2019-06-09 03:16

You might also be able to just switch to use the regular HTTP registry instead of the default HTTPS one by running:

npm config set registry http://registry.npmjs.org/

As mentioned in npm issue 8872

查看更多
迷人小祖宗
3楼-- · 2019-06-09 03:23

As you're not behind a proxy, I think this may be an issue with the SSL Root Certificate Authorities trusted.

Firstly you can try force NPM to use known registrars

npm config set ca ""

If this doesn't work, it's perhaps due to missing certs from the install.

You can try reinstall/upgrade NPM with the appropriate certs by doing the following in order

npm config set ca ""
npm install npm -g
npm config delete ca

If that still fails you might have to forcibly download the missing CA's. Luckily there's a library for fixing this. Unfortunately there's a security pitfall in the process. (I'm open to hearing improvements!).

Firstly, turn off ssl in npm (this is the security pitfall) by using

npm config set strict-ssl false

then you can install

npm install ssl-root-cas

then simply type node and in the REPL type

var sslRootCAs = require('ssl-root-cas/latest')
sslRootCAs.inject()

then turn back on SSL and test

npm config set strict-ssl false
查看更多
登录 后发表回答