1

Apologies if this is a repeat question, but I am new to this. I have installed nodeJS and am trying to install hardhat. I have a Windows 10 laptop.

I followed the instructions here: https://hardhat.org/tutorial/setting-up-the-environment

I am trying to run the following code:

mkdir hardhat-tutorial
cd hardhat-tutorial
npm init --yes
npm install --save-dev hardhat

Then I get the following errors:

npm ERR! code UNABLE_TO_GET_ISSUER_CERT_LOCALLY
npm ERR! errno UNABLE_TO_GET_ISSUER_CERT_LOCALLY
npm ERR! request to https://registry.npmjs.org/hardhat failed, reason: unable to get local issuer certificate

When I search this online it says to try the following solutions:

npm config set strict-ssl false

OR

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

I've done both and rebooted the PC and it doesn't make a difference. Anyone got any ideas of what I can do to resolve this?

Thanks John

JohnB
  • 67
  • 2
  • 13
  • is the laptop managed by some enterprise or are you connected to some corporate network? what is your node.js/npm versions? If you have answers for these, pick a solution from this https://stackoverflow.com/questions/45884752/npm-err-code-unable-to-get-issuer-cert-locally. Got a bunch of solutions here. If none works, leave a comment again – Rajani B May 31 '22 at 09:50
  • Hi - yes it is is a corporate Windows laptop. I've tried the commands above but those don't work. We don't have zScaler. I think I need to look where I can edit the permissions directly? A config file or something? – JohnB May 31 '22 at 11:15

3 Answers3

2

You are running from behind a "deep inspection" web proxy, which issues fake SSL certificates to allow it to inspect your traffic, and although there are probably automated systems to make your browser trust the root CA cert that issues these certificates, npm is not configured to trust that CA.

You should be able to get the CA cert from your browser, the system keychain, or your IT department, and then configure npm to use it with npm config set cafile /path/to/cert.pem

Jason Kohles
  • 597
  • 5
  • 12
0

even if you don't know where the corporate certificate is located you can solve it for a single terminal use by running set NODE_TLS_REJECT_UNAUTHORIZED=0 before running the npm commands it will work for the current terminal session.

or you can run setX NODE_TLS_REJECT_UNAUTHORIZED 0 /m once beware this option as security risks! to cancel this setting you should run REG delete "HKLM\SYSTEM\CurrentControlSet\Control\Session Manager\Environment" /F /V NODE_TLS_REJECT_UNAUTHORIZED .

the best way to solve the problem will be to find the corporate certificate and run the following command SetX NODE_EXTRA_CA_CERTS "path/to/certificate" /m when you change path/to/certificate by the full path.

yehsuf
  • 84
  • 9
-1
Turning off strict ssl: npm config set strict-ssl=false
Changing the registry to http instead of https: npm config set registry http://registry.npmjs.org/
Changing my cafile setting: npm config set cafile /path/to/your/cert.pem
Stop rejecting unknown CAs: set NODE_TLS_REJECT_UNAUTHORIZED=0
Hazrat Gafulov
  • 318
  • 4
  • 9