Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Install package manager behind a corporative proxy #67

Closed
Djaler opened this issue Nov 18, 2021 · 22 comments · Fixed by #69
Closed

Install package manager behind a corporative proxy #67

Djaler opened this issue Nov 18, 2021 · 22 comments · Fixed by #69
Labels
good first issue Good for newcomers

Comments

@Djaler
Copy link
Contributor

Djaler commented Nov 18, 2021

I tried to do, as instance corepack prepare [email protected], but got Internal Error: Error when performing the request.
I think this is because of the proxy. Where I can configure it?
I have proxy setting in .npmrc, also I have HTTP_PROXY and HTTPS_PROXY environment variables

@arcanis
Copy link
Contributor

arcanis commented Nov 18, 2021

At the moment there is no configuration for proxies, but it'd be nice to have

@arcanis arcanis added the good first issue Good for newcomers label Nov 18, 2021
@Djaler
Copy link
Contributor Author

Djaler commented Nov 18, 2021

Can I help you with this?

@arcanis
Copy link
Contributor

arcanis commented Nov 18, 2021

For sure! This is the place where we handle https queries; adding support for HTTPS_PROXY there would be appreciated:

https://github.com/nodejs/corepack/blob/main/sources/httpUtils.ts#L11-L23

@Djaler
Copy link
Contributor Author

Djaler commented Nov 18, 2021

I think we could use https://github.com/gajus/global-agent. And https://github.com/np-maintain/global-tunnel if we need to support node < 10 (I didn't found info about node versions supported by corepack)

@Djaler
Copy link
Contributor Author

Djaler commented Nov 19, 2021

So, I have a two questions:

  1. Should we support node <10?
  2. Where should we get proxy config from? I suggest auto load variables from env (HTTP_PROXY, HTTPS_PROXY, etc) and from .npmrc config

@arcanis
Copy link
Contributor

arcanis commented Nov 19, 2021

Should we support node <10?

I'd go with no, as those version are past LTS.

Where should we get proxy config from? I suggest auto load variables from env (HTTP_PROXY, HTTPS_PROXY, etc)

Env variables are fine, but I'd prefer to hold off on complexifying the configuration by reading the .npmrc (cf this other comment). It opens many questions, and the answers aren't as easy as env configuration.

@BrunoMBento
Copy link

BrunoMBento commented Dec 1, 2021

Hi, there!

I'm having the same problem here. I've installed corepack, enabled it, but can't run yarn. Always get this "Error when performing the request" error, and i'm behind a proxy.

Was this problem solved?

Thanks!

@Djaler
Copy link
Contributor Author

Djaler commented Dec 1, 2021

@BrunoMBento PR with proxy support is created, it only needs to be merged

@BrunoMBento
Copy link

Thanks a lot, @Djaler !

@jonatasrs
Copy link

Same problem, with proxy configured in the environment:

node: v16.13.2
SO: Ubuntu 21.10

Internal Error: Error when performing the request
    at ClientRequest.<anonymous> (/usr/lib/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)

@biandratti
Copy link

I have the same error. Does anyone know any workaround? Thanks!
node: v17.6.0
SO: Ubuntu 21.10

@icyerasor
Copy link

Same problem here.
Workaround for now: don't use corepack i guess:
corepack disable
npm install -g yarn
yarn config set registry YOUR_URL
yarn config set npmRegistryServer YOUR_URL // for yarn2
yarn config set httpProxy localhost:8887 // maybe 🤷‍♂️
And don't forget to delete your local yarn.lock file in the project folder as our industry is fucked up and it caches the initial URLs for each dependency, even if you changed the registry config inbetween 🙄

@mnajafiyazdi-Maya
Copy link

Any updates on this?

By the way, @icyerasor , if I disable the corepack, then even if I install it using npm, I don't have yarn command!
So, your workaround doesn't work for me.

Any other alternative ways?

@kkwoo
Copy link

kkwoo commented Jun 29, 2022

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 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.

@joelstransky
Copy link

In case it helps anyone, our firewall blocks any tarball or exe and while debugging I noticed an attempt on 'https://registry.yarnpkg.com/yarn/-/yarn-1.22.19.tgz' which is causing this error in our case.

@aduh95
Copy link
Contributor

aduh95 commented Jul 27, 2022

In case anyone missed it, as of Corepack 0.11.0, HTTP_PROXY, HTTPS_PROXY, and NO_PROXY are supported through node-proxy-agent.

@capndave
Copy link

capndave commented Jun 2, 2023

I'd love any advice that anyone has for using HTTP_PROXY and other env variables to configure a custom package manager! We're trying to get pnpm to install from a corporate Nexus repo.

@danchenkov
Copy link

In case anyone missed it, as of Corepack 0.11.0, HTTP_PROXY, HTTPS_PROXY, and NO_PROXY are supported through node-proxy-agent.

Could you elaborate a little bit? I am behind proxy, HTTP_PROXY and HTTPS_PROXY environment variables are set, proxy-agent is installed, but no joy installing yarn via corepack:

$ corepack install -g yarn

Internal Error: Error when performing the request to https://repo.yarnpkg.com/tags; for troubleshooting help, see https://github.com/nodejs/corepack#troubleshooting
    at fetch (/usr/local/lib/node_modules/corepack/dist/lib/corepack.cjs:22882:11)
    at async fetchAsJson (/usr/local/lib/node_modules/corepack/dist/lib/corepack.cjs:22896:20)
    at async fetchAvailableVersions2 (/usr/local/lib/node_modules/corepack/dist/lib/corepack.cjs:23002:20)
    at async /usr/local/lib/node_modules/corepack/dist/lib/corepack.cjs:23428:25
    at async Promise.all (index 1)
    at async Engine.resolveDescriptor (/usr/local/lib/node_modules/corepack/dist/lib/corepack.cjs:23425:22)
    at async InstallGlobalCommand.installFromDescriptor (/usr/local/lib/node_modules/corepack/dist/lib/corepack.cjs:23835:22)
    at async InstallGlobalCommand.execute (/usr/local/lib/node_modules/corepack/dist/lib/corepack.cjs:23821:9)
    at async InstallGlobalCommand.validateAndExecute (/usr/local/lib/node_modules/corepack/dist/lib/corepack.cjs:21173:22)
    at async _Cli.run (/usr/local/lib/node_modules/corepack/dist/lib/corepack.cjs:22148:18)

@adurand-ctie
Copy link

In case anyone missed it, as of Corepack 0.11.0, HTTP_PROXY, HTTPS_PROXY, and NO_PROXY are supported through node-proxy-agent.

I would also be interested in some tips on how to use proxy-agent with corepack.
Thanks!

@aduh95
Copy link
Contributor

aduh95 commented Mar 6, 2024

As of Corepack 0.26.0, we're now using proxy-from-env. It should not require anything to install on your end, only setting env variable AFAIK (so HTTPS_PROXY, or ALL_PROXY). I recommend opening a new issue if you're need more help.

@adurand-ctie
Copy link

As of Corepack 0.26.0, we're now using proxy-from-env. It should not require anything to install on your end, only setting env variable AFAIK (so HTTPS_PROXY, or ALL_PROXY). I recommend opening a new issue if you're need more help.

Thanks for your help! I'll open a new issue.

@aep-sunlife
Copy link

corepack 0.28.2 appears to have several remaining glitches concerning proxies / certificate chains.

  • Both corepack... and yarn... silently ignore HTTP_PROXY, HTTPS_PROXY, and NODE_EXTRA_CA_CERTS when installing yarn itself.
  • Both corepack... and yarn... silently ignore httpProxy, httpsProxy, and httpsCaFilePath in .yarnrc.yml when installing yarn itself.
  • Both corepack and yarn silently ignore ~/.npmrc proxy and certificate chain information when installing yarn itself.
  • corepack appears to depend on a dead package: node-proxy-agents. There is a newer package proxy-agents, however that one has open bugs regarding proxy integration. Need HttpsProxyAgent to support setting the CA Cert TooTallNate/proxy-agents#234
  • corepack is self described as experimental, but yarn documentation remarks that installing yarn via traditional npm install -g is hazardous. So yarn is requiring use of an experimental, unstable component to provision yarn.
  • The error handling often obfuscates essential socket level information.
  • Sometimes, the error handling is so bad, that commands like corepack install --global [email protected] present no HTTP response information or socket information at all.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Good for newcomers
Projects
None yet
Development

Successfully merging a pull request may close this issue.