@@ -14,6 +14,9 @@ import {
1414 UnprocessableEntityError ,
1515 sanitizeErrorData ,
1616} from './helpers/errors'
17+ import type cacheableLookupType from 'cacheable-lookup'
18+ import type httpsType from 'node:https'
19+ import type httpType from 'node:http'
1720
1821/**
1922 * Configuration for the keep alive feature
@@ -23,6 +26,12 @@ export type KeepAliveConfig = {
2326 * Whether to keep the connection alive
2427 */
2528 enabled : boolean
29+
30+ /**
31+ * Whether to use the cacheable lookup library for DNS lookups
32+ */
33+ useCacheableLookupDNS ?: boolean
34+
2635 /**
2736 * Maximum number of sockets to keep alive
2837 */
@@ -400,17 +409,17 @@ export const createAxiosInstanceBackend = async (
400409 typeof module !== 'undefined' &&
401410 module . exports
402411 ) {
403- // This is a dynamic import to avoid loading this module in the browser
404- const CacheableLookupLib = await import ( 'cacheable-lookup' )
412+ // Import the module here to avoid loading this module in the browser
413+ const CacheableLookup : typeof cacheableLookupType = require ( 'cacheable-lookup' )
405414
406415 // Create a cacheable lookup instance
407416 // Goal is to make DNS lookup fully async + avoid hitting the limit of 4 UV threads
408417 // See https://marmelab.com/blog/2025/07/28/dns-in-nodejs.html (for example) on the subject
409- const cacheableLookup = new CacheableLookupLib . default ( )
418+ const cacheableLookup = new CacheableLookup ( )
410419
411420 if ( args . baseUrl . startsWith ( 'https' ) ) {
412- // This is a dynamic import to avoid loading the https module in the browser
413- const https = await import ( 'node:https' )
421+ // Import the module here to avoid loading this module in the browser
422+ const https : typeof httpsType = require ( 'node:https' )
414423 // Default values are what we evaluated to be good for our load
415424 const httpsAgent = new https . Agent ( {
416425 keepAlive : true ,
@@ -419,11 +428,13 @@ export const createAxiosInstanceBackend = async (
419428 keepAliveMsecs : args . keepAlive . keepAliveMsecs ?? 60000 ,
420429 } )
421430
422- cacheableLookup . install ( httpsAgent )
431+ if ( args . keepAlive . useCacheableLookupDNS ) {
432+ cacheableLookup . install ( httpsAgent )
433+ }
423434 config . httpsAgent = httpsAgent
424435 } else {
425- // This is a dynamic import to avoid loading the http module in the browser
426- const http = await import ( 'node:http' )
436+ // Import the module here to avoid loading this module in the browser
437+ const http : typeof httpType = require ( 'node:http' )
427438 // Default values are what we evaluated to be good for our load
428439 const httpAgent = new http . Agent ( {
429440 keepAlive : true ,
@@ -432,7 +443,9 @@ export const createAxiosInstanceBackend = async (
432443 keepAliveMsecs : args . keepAlive . keepAliveMsecs ?? 60000 ,
433444 } )
434445
435- cacheableLookup . install ( httpAgent )
446+ if ( args . keepAlive . useCacheableLookupDNS ) {
447+ cacheableLookup . install ( httpAgent )
448+ }
436449 config . httpAgent = httpAgent
437450 }
438451 }
0 commit comments