17

I got below error when trying to build the microsoft driver for nodejs for sql server

gyp info it worked if it ends with ok

gyp info using node-gyp@3.2.1

gyp info using node@5.3.0 | win32 | x64

gyp http GET https://nodejs.org/download/release/v5.3.0/node-v5.3.0-headers.tar.gz

gyp WARN install got an error, rolling back install

gyp ERR! configure error

gyp ERR! stack Error: self signed certificate in certificate chain

gyp ERR! stack at Error (native)

gyp ERR! stack at TLSSocket. (_tls_wrap.js:1057:38)

gyp ERR! stack at emitNone (events.js:67:13)

gyp ERR! stack at TLSSocket.emit (events.js:166:7)

gyp ERR! stack at TLSSocket._finienter code hereshInit

gyp ERR! not ok "

i tried with below workaround but it dint work

1) upgrade your version of npm

npm install npm -g --ca=null

- or -

2) tell your current version of npm to use known registrars  

npm config set ca=""

Can anyone guide me how to resolve this certificate issue

Dilip Reddy
  • 339
  • 2
  • 4
  • 17
  • Is there an antivirus that is blocking npm access? What version of npm are you using currently? Thanks – giri-sh Jan 05 '16 at 10:44
  • npm version is 3.5.2 , yes there is a McAfee antivirus system is corporate network ,Thanks Dilip – Dilip Reddy Jan 05 '16 at 11:04
  • Can you try disabling the antivirus and perform the installation? HTTPS protection can often block npm from building the packages. Thanks – giri-sh Jan 05 '16 at 11:06
  • Since my system is in corporate network i will not be able to do it , is there any other way to bypass it , Thanks Dilip – Dilip Reddy Jan 05 '16 at 11:09

7 Answers7

15

Unfortunately node-gyp doesn't utilize npm's certificate settings.

If you are calling node-gyp, you can updated to the latest node-gyp then utilize a new --cafile parameter to supposedly provide a valid ca certificate.

If you are using npm to install a package that builds itself with node-gyp, your only recourse is a hack to set NODE_TLS_REJECT_UNAUTHORIZED=0 environment variable beforehand, to have it ignore CA certificate issues.

See discussion on github here: https://github.com/nodejs/node-gyp/issues/695

mujimu
  • 1,449
  • 11
  • 11
  • 2
    changes goes into node environment, not into system environment. npm config set NODE_TLS_REJECT_UNAUTHORIZED=0 – MattOpen Jun 14 '18 at 14:29
  • @pixelquadrat Am pretty sure that isn't the case. Using the `npm config` command made no difference for me, whereas using the environment variable got past the issue (...and onto another one but that's a different story!) – Steve Chambers Dec 08 '20 at 16:35
  • Check this link maybe this helped: https://stackoverflow.com/questions/42722457/how-to-prevent-node-gyp-from-downloading-node-headers-tar-gz-and-node-lib-from-i – Naveen Kumar Jun 16 '23 at 08:58
3

For me gyp rebuild could not find binding.gyp and it was trying to download it. Try running: sudo npm install -g --unsafe-perm binding

verses
  • 51
  • 3
3

Came across the same problem when node-gyp starts compiling node.js addons source. And as @mujimu suggested, fixed it setting a shell variable NODE_TLS_REJECT_UNAUTHORIZED value to 0 before executing npm install, as follows:

$ set NODE_TLS_REJECT_UNAUTHORIZED=0
$ npm install
Arpit Aggarwal
  • 27,626
  • 16
  • 90
  • 108
2

Used npm config set strict-ssl false and that fixed the issue.

TT.
  • 15,774
  • 6
  • 47
  • 88
arul pushpam
  • 501
  • 6
  • 6
1

Set your certificate file to be used when doing HTTPS requests using the following command:

npm config set cafile /path/to/your/cert.pem --global
WitnessTruth
  • 539
  • 2
  • 9
  • 27
1

3 steps to solve this if this is related to a corporate proxy:

  1. Retrieve public cert and convert them to .pem format. The file looks like this. -----BEGIN CERTIFICATE----- ABCDEFGHIJKLMNOPQRSTBLABLA...MORECHARSHERE -----END CERTIFICATE-----\n------BEGIN CERTIFICATE ... etc depends on your company
  2. Store them somewhere on your pc. I store them in my repo
  3. In a terminal execute NODE_EXTRA_CA_CERTS=/home/<yourUser>/git/myproject/certs/myBundle.pem npm i --quiet

For Windows you've got to change that to: NODE_EXTRA_CA_CERTS=C:\Users\<yourUser>\git\myproject\certs\myBundle.pem npm i --quiet

Matthis Kohli
  • 1,877
  • 1
  • 21
  • 23
-1

Try uninstalling Angular/cli first and installing node-gyp and then try reinstalling Angular cli

npm uninstall -g @angular/cli
npm install -g node-gyp
npm install -g @angular/cli

It works perfectly