undici: Error: connect ECONNREFUSED ::1:19001
Bug Description
(node:1800) ExperimentalWarning: Custom ESM Loaders is an experimental feature. This feature could change at any time
(Use `node --trace-warnings ...` to show where the warning was created)
(node:1800) DeprecationWarning: Obsolete loader hook(s) supplied and will be ignored: getFormat, transformSource
node:internal/process/esm_loader:91
internalBinding('errors').triggerUncaughtException(
^
Error: connect ECONNREFUSED ::1:19001
at TCPConnectWrap.afterConnect [as oncomplete] (node:net:1195:16) {
errno: -4078,
code: 'ECONNREFUSED',
syscall: 'connect',
address: '::1',
port: 19001
}
import { ProxyAgent, request } from "undici";
const proxyAgent = new ProxyAgent("http://localhost:19001");
const {
statusCode,
body,
headers,
} = await request("http://www.baidu.com", { dispatcher: proxyAgent });
console.log("response received", statusCode); // response received 200
console.log(headers);
for await (const data of body) {
console.log("data", data.toString("utf8")); // data foo
}
Reproducible By
npx esmo "C:\Documents\测试\test\test.ts"
Expected Behavior
(node:2384) ExperimentalWarning: Custom ESM Loaders is an experimental feature. This feature could change at any time
(Use `node --trace-warnings ...` to show where the warning was created)
(node:2384) DeprecationWarning: Obsolete loader hook(s) supplied and will be ignored: getFormat, transformSource
response received 307
{
location: 'https://www.baidu.com/',
vary: 'Accept-Encoding',
'content-length': '0',
date: 'Thu, 05 May 2022 07:24:45 GMT'
}
Logs & Screenshots
Environment
nodejs v18.1.0 undici 5.1.1
Additional context
About this issue
- Original URL
- State: closed
- Created 2 years ago
- Comments: 15 (4 by maintainers)
If a site is misconfigured, a site is misconfigured. If they mess up A records, it won’t be reachable for folks on IPv4-only as well.
However, Node v20 comes with Happy Eyeballs support which should mitigate this problem.