diff --git a/packages/vite/src/node/utils.ts b/packages/vite/src/node/utils.ts index f8c7154a879b39..8c3bbb2cd79385 100644 --- a/packages/vite/src/node/utils.ts +++ b/packages/vite/src/node/utils.ts @@ -922,17 +922,21 @@ export function unique(arr: T[]): T[] { * Even if defaultResultOrder is `ipv4first`, `dns.lookup` result maybe same. * For example, when IPv6 is not supported on that machine/network. */ -export async function getLocalhostAddressIfDiffersFromDNS(): Promise< - string | undefined -> { - const [nodeResult, dnsResult] = await Promise.all([ +export function getLocalhostAddressIfDiffersFromDNS(): + | Promise + | undefined { + if (dns.getDefaultResultOrder() === 'verbatim') { + return undefined + } + return Promise.all([ dns.lookup('localhost'), dns.lookup('localhost', { verbatim: true }), - ]) - const isSame = - nodeResult.family === dnsResult.family && - nodeResult.address === dnsResult.address - return isSame ? undefined : nodeResult.address + ]).then(([nodeResult, dnsResult]) => { + const isSame = + nodeResult.family === dnsResult.family && + nodeResult.address === dnsResult.address + return isSame ? undefined : nodeResult.address + }) } export function diffDnsOrderChange(