Encountering SSL Certificate Verification Error with npm Install

Hello everyone!

I’ve been facing a frustrating issue while trying to install packages in my Node.js project using npm install. I keep getting this error:

npm ERR! RequestError: unable to get local issuer certificate
npm ERR! at ClientRequest.<anonymous> (file:///path/to/node_modules/got/dist/source/core/index.js:790:107)
npm ERR! at Object.onceWrapper (node:events:622:26)
npm ERR! at ClientRequest.emit (node:events:519:35)
npm ERR! at emitErrorEvent (node:_http_client:104:11)
npm ERR! at TLSSocket.socketErrorListener (node:_http_client:518:5)
npm ERR! at TLSSocket.emit (node:events:507:28)
npm ERR! at emitErrorNT (node:internal/streams/destroy:170:8)
npm ERR! at emitErrorCloseNT (node:internal/streams/destroy:129:3)
npm ERR! at process.processTicksAndRejections (node:internal/process/task_queues:90:21)
npm ERR! at TLSSocket.onConnectSecure (node:_tls_wrap:1679:34)
npm ERR! at TLSSocket.emit (node:events:507:28)
npm ERR! at TLSSocket._finishInit (node:_tls_wrap:1078:8)
npm ERR! at ssl.onhandshakedone (node:_tls_wrap:864:12)

Context:
I’m working in a Node.js environment and have dependencies that I need to install. The RequestError is due to SSL/TLS certificate issues, preventing successful installation of packages.

Here’s what I’ve done to try and fix it:

  1. Disabling SSL Verification: Tried running NODE_TLS_REJECT_UNAUTHORIZED=0 npm install, but it didn’t help.
  2. Proxy Settings: My setup might involve a proxy, so I checked and updated the proxy settings in the .npmrc file, but still encountered the error.
  3. Clear npm Cache: I executed npm cache clean --force, yet the problem persists.
  4. Using --legacy-peer-deps: Tried installing with the --legacy-peer-deps flag, but it also didn’t resolve my issue.
  5. Setting Custom CA Certificates: Attempted to use NODE_EXTRA_CA_CERTS to point to a custom CA certificate, but this didn’t solve the problem either.

Additional Details:

  • Node.js version is 23.10.0.
  • The error appears when attempting to download dependencies from the internet.
  • I suspect this might be linked to working in a corporate network due to the corporate proxy.

Help Needed:
Has anyone experienced this before? What solutions have worked to navigate SSL validation issues with npm and Node.js?

Corporate networks are such a pain for this. Switch to yarn instead of npm - it handles SSL differently and might get through. Also check if your company runs Zscaler or similar proxy software. They usually need specific configs to make node tools work.

Had this exact problem at my old job. Windows certificate store wasn’t accessible to Node.js. The win-ca package fixed it - it bridges Windows certificates and Node. Run npm install -g win-ca then add require('win-ca') at the top of your main file or create a .js file that imports it before running npm commands. Also update npm with npm install -g npm@latest since newer versions handle corporate SSL better. If you’re still stuck, ask IT for the exact proxy config including auth details - sometimes .npmrc needs their specific format.

I encountered a similar SSL issue while working behind a corporate firewall. The root of the problem was that our network was intercepting SSL traffic and replacing the certificates with its own. To resolve this, I reached out to our IT team for the corporate root certificate. After obtaining it, I configured npm to recognize that certificate using the command npm config set cafile /path/to/certificate.pem. As an alternative, if your company has an internal npm registry, consider using that to bypass SSL verification issues altogether. Avoid setting NODE_TLS_REJECT_UNAUTHORIZED=0 as it compromises security. The certificate method is much more secure.