-
Notifications
You must be signed in to change notification settings - Fork 179
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
Using corepack behind corporate proxy and injected certificate #417
Comments
Probably related to nodejs/undici#2200. |
To overcome this, should I try |
Could there be that you need to specify a |
Still no luck, even with COREPACK_NPM_REGISTRY. |
Seeing the same issue here with corepack 0.25.x |
I've been digging a little more into this issue as I also use a proxy (squid-cache, no proxy auth, no tls inspection). First, I don't believe this is an injected certificate issue since my proxy only relays connections out without any TLS inspection. Second, since I fully control my local DNS server and the proxy, I have noticed no connection attempt is made to connect to the defined proxy. However, inspecting the Rolling backward, I tried to find what were the changes introduced between Last, I found that downgrading to corepack Then upgrading back to Tagging both @merceyz and @aduh95 who have authored the PR mentioned above for visibility. When dumped, my ProxyAgent looked like this.
Hoping this will be helpful. |
thank you :) |
@aureq thanks for the detailed report! Can you also confirm whether you're able to reproduce with a simple |
@aduh95 I'm trying to, but having some typing issues... Could you provide some guidance or help please? First, I reused most of the code that's present in CorePack to save some time (the code I mentioned in my previous comment). From the code below, vscode complains with the following error: But also, I'm a little puzzled as to why Any suggestions welcome. async function getProxyAgent(input: string | URL) {
const {getProxyForUrl} = await import(`proxy-from-env`);
// @ts-expect-error - The internal implementation is compatible with a WHATWG URL instance
const proxy = getProxyForUrl(input);
if (!proxy) return undefined;
// Doing a deep import here since undici isn't tree-shakeable
const {default: ProxyAgent} = (await import(
// @ts-expect-error No types for this specific file
`undici/lib/proxy-agent.js`
)) as { default: typeof import('undici').ProxyAgent };
return new ProxyAgent(proxy);
}
async function myFetch(input: string | URL, init?: RequestInit) {
const agent = await getProxyAgent(input);
console.error(agent);
let response;
try {
response = await globalThis.fetch(input, {
...init,
dispatcher: agent, // <-- error
});
} catch (error) {
console.error(error);
throw new Error(`Error when performing the request to ${input}`);
}
}
fetch("https://checkip.amazonaws.com"); {
"name": "gh-417",
"main": "index.ts",
"engines": {
"node": "^18.17.1 || >=20.10.0"
},
"devDependencies": {
"@types/node": "^20.10.0",
"@types/proxy-from-env": "^1",
"proxy-from-env": "^1.1.0",
"undici": "^6.6.1",
"typescript": "^5.0.4",
"ts-node": "^10.0.0"
}
} |
As documented in https://undici.nodejs.org/#/docs/api/ProxyAgent,
That's probably because Does the above code reproduce the error? Could you also try to reproduce with URLs Corepack uses, e.g. https://repo.yarnpkg.com/4.0.0/packages/yarnpkg-cli/bin/yarn.js or https://registry.yarnpkg.com/yarn/latest. |
@aduh95 Thanks for the information. It's probably worth mentioning I'm not a JS/TS developer. With that said, I've simplified my example and the code shared below works as expected. The connection is made to my proxy and the content appears to be retrieved correctly. So, in my example, But FWIW, the issue may be on corepack's side. import * as proxyFromEnv from "proxy-from-env"
import * as proxyAgent from "undici"
async function getProxyAgent(input: string) {
const proxy = proxyFromEnv.getProxyForUrl(input);
if (!proxy) return undefined;
return new proxyAgent.ProxyAgent(proxy);
}
async function myFetch(input: string, init?: RequestInit) {
const agent = await getProxyAgent(input);
const u = new URL(input);
let response;
try {
proxyAgent.fetch
response = await proxyAgent.fetch(u, {
dispatcher: agent,
});
} catch (error) {
console.error(error);
throw new Error(`Error when performing the request to ${input}`);
}
console.log(response);
}
const res = myFetch("https://checkip.amazonaws.com"); |
Hi, I have the same issue and had a look and have a bit more information My environmentNode 18.19.1 1. Uncovering the real errorThe error I got initially did not help much:
So I added a
So what we get is This error is internal to undici (the bundled library) but is triggered when calling
2. A short reproduction:{
"devDependencies": {
"proxy-from-env": "^1.1.0",
"undici": "6.6.2"
}
} import { getProxyForUrl } from "proxy-from-env";
import ProxyAgent from "undici/lib/proxy-agent.js";
//import { fetch } from "undici/lib/fetch/index.js";
//import { ProxyAgent, fetch } from "undici";
async function getProxyAgent(input) {
const proxy = getProxyForUrl(input);
if (!proxy) return undefined;
return new ProxyAgent(proxy);
}
async function myFetch(input, init) {
const agent = await getProxyAgent(input);
try {
const response = await globalThis.fetch(input, {
dispatcher: agent,
});
console.log(response.status);
} catch (error) {
console.error(error);
throw new Error(`Error when performing the request to ${input}`);
}
}
myFetch("https://repo.yarnpkg.com/4.1.1/packages/yarnpkg-cli/bin/yarn.js"); Using this with a proxy will yield the error we saw above:
But by changing the following import, it works OK : - import ProxyAgent from "undici/lib/proxy-agent.js";
+ import { ProxyAgent } from "undici"; My understanding is that some other file imported by undici has side effects and would get the library to work fine. |
This really needs to be fixed ... we do have the exact same error ... |
I have the same issue:
But my corepack version is 0.23.0, so downgrade to 24 is not possible, I have an even lower version. |
I Upgraded a project from Node 16 to 20. Our build is made in a custom Docker image. I think that the bugged version of corepack is shipped by default in Node 20. I ended up upgradind corepack to 0.27.0 For reference: RUN corepack enable && npm install -g [email protected] && corepack install --global [email protected] Works well behind our proxy. |
Still encountering this issue. Everything works fine locally. It was also working fine in the cloud too. Now, I only encounter the issue when i'm deploying my api (docker image) onto GCP cloud run. i get this error : My corepack version locally : 0.17.2 (installed using home brew)
|
@devbydixon as stated above, you need to upgrade your corepack to |
Hi,
I'm willing to use API Platform (https://api-platform.com/) and the Dockerfile of the pwa component requires corepack:
The base image is node:20-alpine.
I'm behind a corporate proxy, so I've added the following before using corepack:
We also have a "traffic interceptor" that watches the whole traffic, so I added its certificate (which is already injected in the image):
RUN set NODE_EXTRA_CA_CERTS=/usr/local/share/ca-certificates/etat.crt
However, I'm still running into issues and receive the error below upon executing
corepack prepare --activate pnpm@latest
:Anybody could help me figure out what I'm missing here?
Thanks in advance.
Adrien.
The text was updated successfully, but these errors were encountered: