From b10128e9d44ad459e879e4300d78f17ef722e89b Mon Sep 17 00:00:00 2001 From: dirkwa Date: Sat, 24 Jan 2026 08:49:12 +1200 Subject: [PATCH] Fix Node.js 20+ AggregateError with @cypress/request libraries Disable autoSelectFamily (Happy Eyeballs RFC 6555) to prevent AggregateError crashes in Node-RED nodes using @cypress/request (e.g., node-red-contrib-telegrambot). Node.js 20+ enables autoSelectFamily by default, which tries IPv4 and IPv6 connections simultaneously. When both fail, it throws AggregateError which older HTTP libraries don't handle properly. Fixes issues with: - node-telegram-bot-api (uses @cypress/request) - Other Node-RED nodes using deprecated request libraries References: - https://github.com/yagop/node-telegram-bot-api/issues/1193 - https://github.com/nodejs/node/pull/46790 --- index.js | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/index.js b/index.js index 7defb16..d7684dd 100644 --- a/index.js +++ b/index.js @@ -14,6 +14,21 @@ * limitations under the License. */ +/** + * Workaround for Node.js 20+ "Happy Eyeballs" (RFC 6555) causing AggregateError + * in libraries using @cypress/request (e.g., node-telegram-bot-api). + * + * Node.js 20+ enables autoSelectFamily by default, which tries IPv4 and IPv6 + * simultaneously. When connections fail, it throws AggregateError which older + * HTTP libraries don't handle properly. + * + * See: https://github.com/yagop/node-telegram-bot-api/issues/1193 + * https://github.com/nodejs/node/pull/46790 + */ +const net = require('net') +if (typeof net.setDefaultAutoSelectFamily === 'function') { + net.setDefaultAutoSelectFamily(false) +} const RED = require("node-red") const compareVersions = require('compare-versions')