Last updated: Apr 23, 2023
Reading time·4 min
Disable the strict-ssl
key to resolve the error "npm ERR! unable to get local
issuer certificate".
When the strict-ssl
key is set to false
, NPM doesn't perform SSL key
validation when making requests to the registry via https
.
The article addresses the following errors:
The error occurs when you run the npm install
command and try to download a
package from a server with an HTTPS connection using a self-signed or an invalid
certificate.
The easiest way to solve the error is to set the
strict-ssl key to
false
.
npm config set strict-ssl false npm config get strict-ssl
If you use yarn
, issue the following command instead.
yarn config set strict-ssl false
Try to rerun the npm install
or yarn install
command after disabling the
strict-ssl
key.
# with NPM npm install # or with YARN yarn install
If you are running the npm install command from behind a proxy would like to clear the proxy or install modules from behind the proxy, check out the following article.
npm install
command.NODE_TLS_REJECT_UNAUTHORIZED
environment variable to 0
If the error persists, try to set the NODE_TLS_REJECT_UNAUTHORIZED
environment
variable to 0
.
If the environment variable is set to 0
, certificate validation is disabled
for TLS connections.
Note that setting the environment variable to 0
makes TLS and HTTPS insecure.
If you use bash or zsh
, you would issue the following command.
# for bash or ZSH export NODE_TLS_REJECT_UNAUTHORIZED=0
If you are on Windows and use CMD or PowerShell, issue one of the following commands.
# for CMD set NODE_TLS_REJECT_UNAUTHORIZED=0 # for PowerShell $env:NODE_TLS_REJECT_UNAUTHORIZED="0"
Try to rerun the npm install
command after making the change.
If the error persists, try to update your NPM registry.
npm config set registry http://registry.npmjs.org/
Notice that the command uses the HTTP version of the NPM registry and not the HTTPS version.
This should resolve the error as you aren't trying to download a package from a server with an HTTPS connection using a self-signed or an invalid certificate.
Try to rerun the npm install
command after making the change.
# with NPM npm install # or with YARN yarn install
If the error is resolved, you can try to flip your strict-ssl
key to true
and test if that works.
npm config set strict-ssl true npm config get strict-ssl
You can always set the key back to false
if the error occurs.
npm config set strict-ssl false npm config get strict-ssl
--unsafe-perm
flag when issuing the npm install
commandIf the error persists, try to set the --unsafe-perm
flag when issuing the npm
install command.
npm install --unsafe-perm # or when installing a specific module npm install axios --unsafe-perm
The --unsafe-perm
flag forces npm
to download the binary files of the
packages to your project.
NODE_EXTRA_CA_CERTS
environment variableIf the error persists, you might be running into issues with your company's proxy.
If that's the case, you can:
The certificate file will likely have a .pem
or .cer
extension.
# on macOS and Linux export NODE_EXTRA_CA_CERTS="/absolute/path/to/your/CA/cert.pem" # on Windows (CMD) set NODE_EXTRA_CA_CERTS="C:\Users\YOUR_USER\cert.pem"
You can also set the environment variable in your ~/.bashrc
file or
~/.bash_profile
if you are on macOS or Linux.
This way you won't have to rerun the command in every shell session.
sudo gedit ~/.bashrc sudo gedit ~/.bash_profile sudo gedit ~/.zshrc
Make sure to source your profile file if end up setting the environment variable.
source ~/.bashrc source ~/.bash_profile source ~/.zshrc
If you are on Windows, you can set the environment variable in your system's environment variables.
If you need to clear your proxy settings or install a module from behind a proxy, check out the following article.
You can learn more about the related topics by checking out the following tutorials: