Skip to content

Commit 8c696de

Browse files
fix(useStrapiClient): import dns module only in development (#370)
Co-authored-by: Benjamin Canac <[email protected]>
1 parent 8a8b35d commit 8c696de

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

src/runtime/composables/useStrapiClient.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import type { FetchError, FetchOptions } from 'ofetch'
22
import { stringify } from 'qs'
3-
import dns from 'dns'
43
import type { Strapi4Error } from '../types/v4'
54
import type { Strapi3Error } from '../types/v3'
65
import { useStrapiUrl } from './useStrapiUrl'
@@ -9,8 +8,11 @@ import { useStrapiToken } from './useStrapiToken'
98
import { useNuxtApp } from '#imports'
109

1110
// Fixes `ECONNREFUSED` on Node 18: https://github.com/node-fetch/node-fetch/issues/1624#issuecomment-1407717012
11+
// Import dns only if running in a server environment during development
1212
if (process.server && process.dev) {
13-
dns.setDefaultResultOrder('ipv4first')
13+
import('dns')
14+
.then((dns) => dns.setDefaultResultOrder('ipv4first'))
15+
.catch((error) => console.error('Error importing dns module:', error))
1416
}
1517

1618
const defaultErrors = (err: FetchError) => ({

0 commit comments

Comments
 (0)