From 8c696de361e58289d893a95e39f031204a9a7466 Mon Sep 17 00:00:00 2001 From: Ramzi Youssef Date: Tue, 28 Nov 2023 11:05:01 +0100 Subject: [PATCH] fix(useStrapiClient): import `dns` module only in development (#370) Co-authored-by: Benjamin Canac --- src/runtime/composables/useStrapiClient.ts | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/runtime/composables/useStrapiClient.ts b/src/runtime/composables/useStrapiClient.ts index 79dc715f..e5debbf0 100644 --- a/src/runtime/composables/useStrapiClient.ts +++ b/src/runtime/composables/useStrapiClient.ts @@ -1,6 +1,5 @@ import type { FetchError, FetchOptions } from 'ofetch' import { stringify } from 'qs' -import dns from 'dns' import type { Strapi4Error } from '../types/v4' import type { Strapi3Error } from '../types/v3' import { useStrapiUrl } from './useStrapiUrl' @@ -9,8 +8,11 @@ import { useStrapiToken } from './useStrapiToken' import { useNuxtApp } from '#imports' // Fixes `ECONNREFUSED` on Node 18: https://github.com/node-fetch/node-fetch/issues/1624#issuecomment-1407717012 +// Import dns only if running in a server environment during development if (process.server && process.dev) { - dns.setDefaultResultOrder('ipv4first') + import('dns') + .then((dns) => dns.setDefaultResultOrder('ipv4first')) + .catch((error) => console.error('Error importing dns module:', error)) } const defaultErrors = (err: FetchError) => ({