stack "Error: self signed certificate in certificate chain" when trying to build 'node-gyp configure'
Asked Answered
B

8

19

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 [email protected]

gyp info using [email protected] | 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

Bahaism answered 5/1, 2016 at 10:7 Comment(4)
Is there an antivirus that is blocking npm access? What version of npm are you using currently? ThanksAntinomian
npm version is 3.5.2 , yes there is a McAfee antivirus system is corporate network ,Thanks DilipBahaism
Can you try disabling the antivirus and perform the installation? HTTPS protection can often block npm from building the packages. ThanksAntinomian
Since my system is in corporate network i will not be able to do it , is there any other way to bypass it , Thanks DilipBahaism
H
16

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

Hubby answered 28/1, 2016 at 19:22 Comment(3)
changes goes into node environment, not into system environment. npm config set NODE_TLS_REJECT_UNAUTHORIZED=0Betseybetsy
@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!)Recorder
Check this link maybe this helped: #42722957Fauna
U
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

Understandable answered 31/5, 2017 at 19:30 Comment(0)
B
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
Barocchio answered 3/9, 2019 at 11:15 Comment(0)
M
3

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

Manamanacle answered 4/10, 2021 at 9:4 Comment(1)
How to retrieve the public cert and convert them to .pem format?Shebeen
B
2

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
Barrus answered 20/9, 2019 at 14:18 Comment(2)
doesn't work with node-gypJaimiejain
@Jaimiejain sorry my friend! O solved the mentioned issue on 2019. The node-gyp error appeared to me when I wasn't configured Python 3 and the visual C++ SDK on my windows.Barrus
D
2

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

Destroyer answered 14/12, 2019 at 7:45 Comment(2)
NOPE same error, Turned OFF VPN. Boom! it worked.Tahitian
Please do NOT do this. Man in the middle attacks are real.Dineen
T
0

Only thing that worked for me was to use the NODE_EXTRA_CA_CERTS environment variable to pass in the self-signed certificate. node-gyp doesn't look at the config files for npm nor at any of npms environment variables. But using the NODE env var does seem to get through.

Therapeutics answered 24/1, 2024 at 5:32 Comment(0)
B
-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

Bowler answered 27/11, 2021 at 6:40 Comment(1)
NOPE same error, Turned OFF VPN. Boom! it worked.Tahitian

© 2022 - 2025 — McMap. All rights reserved.