Skip to content

Commit 08c787a

Browse files
fix: rework how modules are imported...
1 parent d081e3d commit 08c787a

2 files changed

Lines changed: 14 additions & 7 deletions

File tree

clients/javascript/lib/baseClient.ts

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -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
@@ -400,17 +403,17 @@ export const createAxiosInstanceBackend = async (
400403
typeof module !== 'undefined' &&
401404
module.exports
402405
) {
403-
// This is a dynamic import to avoid loading this module in the browser
404-
const CacheableLookupLib = await import('cacheable-lookup')
406+
// Import the module here to avoid loading this module in the browser
407+
const CacheableLookup: typeof cacheableLookupType = require('cacheable-lookup')
405408

406409
// Create a cacheable lookup instance
407410
// Goal is to make DNS lookup fully async + avoid hitting the limit of 4 UV threads
408411
// See https://marmelab.com/blog/2025/07/28/dns-in-nodejs.html (for example) on the subject
409-
const cacheableLookup = new CacheableLookupLib.default()
412+
const cacheableLookup = new CacheableLookup()
410413

411414
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')
415+
// Import the module here to avoid loading this module in the browser
416+
const https: typeof httpsType = require('node:https')
414417
// Default values are what we evaluated to be good for our load
415418
const httpsAgent = new https.Agent({
416419
keepAlive: true,
@@ -422,8 +425,8 @@ export const createAxiosInstanceBackend = async (
422425
cacheableLookup.install(httpsAgent)
423426
config.httpsAgent = httpsAgent
424427
} else {
425-
// This is a dynamic import to avoid loading the http module in the browser
426-
const http = await import('node:http')
428+
// Import the module here to avoid loading this module in the browser
429+
const http: typeof httpType = require('node:http')
427430
// Default values are what we evaluated to be good for our load
428431
const httpAgent = new http.Agent({
429432
keepAlive: true,

clients/javascript/tests/helpers/fixtures.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@ export const setupAccount = async (options?: { timeout?: number }) => {
1515

1616
const config: Parameters<typeof NitteiClient>[0] = {
1717
apiKey: account.secretApiKey,
18+
// Test the keep alive feature at the same time
19+
keepAlive: {
20+
enabled: true,
21+
},
1822
}
1923
if (options?.timeout) {
2024
config.timeout = options.timeout

0 commit comments

Comments
 (0)