Closed marinedayo closed 3 months ago
corepack is part of nodejs
package distributed by NodeSource.
I'm affected by the same issue after upgrade to nodejs=20.12.0-1nodesource1 package.
To downgrade:
sudo apt install nodejs=20.11.1-1nodesource1
Yes, I am also using nodejs distributed by NodeSource. I appended the version information to my report.
Probably import ProxyAgent
from undici/index.js
instead of undici/lib/proxy-agent.js
, e.g. as below:
diff --git a/sources/httpUtils.ts b/sources/httpUtils.ts
index e995d1e..b856099 100644
--- a/sources/httpUtils.ts
+++ b/sources/httpUtils.ts
@@ -100,11 +100,7 @@ async function getProxyAgent(input: string | URL) {
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 };
+ const {ProxyAgent} = await import(`undici`);
return new ProxyAgent(proxy);
}
Probably import
ProxyAgent
fromundici/index.js
instead ofundici/lib/proxy-agent.js
AFAICT it should not have any effect – except making the bundle size bigger. But it's certainly something we can try, we'd just need a way to reproduce the issue first so we can validate if that has any effect.
@aduh95 I'm trying to reproduce. Is it the way to reproduce that you expected?
yarn install
yarn add proxy --dev
yarn build
tests/issue444.test.ts
, described below.yarn test -- issue444
import {afterAll, beforeAll, describe, expect, it} from '@jest/globals';
import process from 'node:process';
import { createProxy } from 'proxy'; // Need `yarn add proxy --dev`.
import type { ProxyServer } from 'proxy';
import { fetchAsJson } from '../sources/httpUtils';
describe(`reproduce issue #444`, () => {
let proxy: ProxyServer;
beforeAll((done) => {
proxy = createProxy();
proxy.listen(done);
})
afterAll((done) => {
proxy.close(done);
})
it(`without proxy settings`, async () => {
await expect(fetchAsJson(`https://registry.npmjs.org/yarn`)).resolves.toEqual(expect.anything());
});
it(`with proxy settings`, async () => {
process.env.HTTPS_PROXY = `http://localhost:${proxy.address().port}`;
await expect(fetchAsJson(`https://registry.npmjs.org/yarn`)).resolves.toEqual(expect.anything());
// TODO: Test fails.
// Received promise rejected instead of resolved
// Rejected to value: [Error: Error when performing the request to https://registry.npmjs.org/yarn; for troubleshooting help, see https://github.com/nodejs/corepack#troubleshooting]
});
});
Looks like the same reason as here currently in discussion. So my issue is closed.
Duplicate of https://github.com/nodejs/corepack/issues/417
Error when downloading yarn with proxy settings.
Details with
NODE_DEBUG
are below:this[kClient].connect is not a function
error has occurred.corepack imports
undici/lib/proxy-agent.js
to useProxyAgent
, butconnect
function is not found here.https://github.com/nodejs/corepack/blob/v0.26.0/sources/httpUtils.ts#L66-L81 https://github.com/nodejs/undici/blob/v6.6.2/lib/proxy-agent.js https://github.com/nodejs/undici/blob/v6.6.2/lib/dispatcher-base.js https://github.com/nodejs/undici/blob/v6.6.2/lib/dispatcher.js
After searching, I found that
connect
function is assigned toDispatcher
onindex.js
.https://github.com/nodejs/undici/blob/v6.6.2/index.js#L24 https://github.com/nodejs/undici/blob/v6.6.2/lib/api/index.js https://github.com/nodejs/undici/blob/v6.6.2/lib/api/api-connect.js
I hope the above report will help to resolve this issue.