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

Dilip Reddy picture Dilip Reddy · Jan 5, 2016 · Viewed 22.9k times · Source

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

Answer

mujimu picture mujimu · Jan 28, 2016

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