Yarn
Published on 2023-03-28Table of contents
What is it?
Yarn is an alternative to npm as package manager for the Node.js runtime.
You can always check the general troubleshooting guide before continuing.
Issue sample
The error might look like this when using Yarn:
Yarn 1.x
...
Trace:
Error: unable to get local issuer certificate
at TLSSocket.onConnectSecure
.. <stack-trace> ..
...
Yarn 2.x
...
YN0001: │ GotError: unable to get local issuer certificate
...
All Platforms
Yarn 1.x
Yarn 1.x takes many configurations directly from Npm by reading the .npmrc
and supports the Node.js environment variables. For that reason you can follow the guid for npm here.
Yarn 2.x
Yarn 2.x doesn’t use the configuration from your .npmrc
files anymore; it instead reads all of the configuration from the .yarnrc.yml
files whose available settings can be found here. The .yarnrc.yml
file must be placed inside your Node.js project and not inside your user directory in order to work correctly.
This means that configurations for certificates must be done inside .yarnrc.yml
. You can configure Yarn to use a central trusted CA certificate bundle file in pem - Base64 format using the following entry in the config file:
# .yarnrc.yml
caFilePath: "<path to pem file>"
The path to the pem file can be absolute or relative.
Another configuration would be httpsCertFilePath
which works like caFilePath
but for the whole SSL certificate chain and not only the trusted root CA certificate. So if you have problems with intermediate certificates, this would be the place to check.
Do not use settings like yarn config set enableStrictSsl false
or npm config set strict-ssl false
because they disable the security feature completely even if you are using a self-signed certificate. It is always better to secure the SSL connection by making a certificate known to npm/Node.js.