6

When I try to install yarn, I've got the following output:

Internal Error: Error when performing the request
    at ClientRequest.<anonymous> (C:\Program Files\nodejs\node_modules\corepack\dist\corepack.js:3937:20)
    at ClientRequest.emit (node:events:390:28)
    at TLSSocket.socketErrorListener (node:_http_client:447:9)
    at TLSSocket.emit (node:events:390:28)
    at emitErrorNT (node:internal/streams/destroy:157:8)
    at emitErrorCloseNT (node:internal/streams/destroy:122:3)
    at processTicksAndRejections (node:internal/process/task_queues:83:21) 
jonrsharpe
  • 115,751
  • 26
  • 228
  • 437
  • 1
    I'm having the same issue and `yarn set version stable` does not solve it. But "install" may not be the right description of this step, maybe "initialize" is a better word? How did you install yarn? I used corepack per the instructions on the yarn site. This error happens both when running `yarn` in an existing repo, and when running `yarn init -2` in an empty folder. This is all a fresh setup on a new computer. – efreed Feb 24 '22 at 16:15

3 Answers3

6

TL;DR

  • Create a custom CA certificate file (in this example c:\temp\combo.ca.cer) containing BASE64-encoded DERs of all certs your corporate network security solution is presenting to Node.js when Node.js makes HTTPS requests
  • set NODE_EXTRA_CA_CERTS=c:\temp\combo.ca.cer
  • corepack enable
  • yarn set version stable

Root Cause Analysis

I had the "Internal Error: Error when performing the request" at "corepack.js:3937:20" like everyone who's been here so I looked in line 3937 and discovered it was a vanilla https.get call. I stuck in some extra debugging into corepack.js to see what was being accessed and discovered it was failing trying to reach "https://registry.npmjs.com/pnpm".

I navigated to "https://registry.npmjs.com/pnpm" in my web browser and discovered my corporate environment let it load up with no errors. So I fired up Node JS and issued to see what would happen:

https.get("https://registry.npmjs.com/pnpm", {}, res => console.log(res));

I received a "unable to get local issuer certificate" error. In my corporate environment, there's a security solution that injects it's own self-signed certificates into responses from any outbound https requests. What that means for me is that I need to instruct anything issuing https requests (eg Node.js and curl) to use a custom CA certificate file.

To get corepack to work, I first hard-coded a custom CA certificate file into corepack.js and while it's pretty ugly, it did work. A bit of further digging around I found the NODE_EXTRA_CA_CERTS environment variable option used by Node.js so also tried the following in a Administrator-privileged cmd session with success (also removing the corepack.js hack I made earlier):

set NODE_EXTRA_CA_CERTS=c:\temp\combo.ca.cer
corepack enable
yarn set version stable

The combo.ca.cer was constructed by navigating to https://registry.npmjs.com/pnpm and exporting all the CA certs (root and any intermediate CA certs) to text files and copy-pasting the contents of all the CA cert files into a single text file called combo.ca.cer. I used advice from https://stackoverflow.com/a/44726189 to create my custom CA cert file.

Kevin Woo
  • 101
  • 1
  • 4
1

As part of the initial setup of a work computer, I got this same error. Even a clean run of yarn (yarn init -2 in an empty folder) would cause the error.

Turning off my VPN made yarn work as expected.

Googling the error lead me to this page which got me to suspect the VPN. https://github.com/nodejs/corepack/issues/67

efreed
  • 991
  • 11
  • 18
-2

I had the same problem and for me it was solved by running yarn set version stable.

  • Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Jan 06 '22 at 11:54