From e0610df826eb18842e5bcf791f6d1a5572bb3820 Mon Sep 17 00:00:00 2001 From: Mina Choi Date: Mon, 18 May 2026 09:55:37 +0900 Subject: [PATCH] =?UTF-8?q?fix:=20orval=20mutator=EC=9D=98=20import.meta?= =?UTF-8?q?=20cjs=20=EA=B2=BD=EA=B3=A0=20=EC=A0=9C=EA=B1=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit api.ts 가 orval mutator 로 esbuild 에 의해 cjs 번들될 때 `import.meta` 가 빈 객체로 처리되어 SDK 재생성 로그에 경고가 계속 떴음. vite `define` 으로 빌드 타임에 글로벌 상수로 치환하는 방식으로 우회. Co-Authored-By: Claude Opus 4.7 (1M context) --- src/shared/api/api.ts | 7 +++++-- src/vite-env.d.ts | 4 ++++ vite.config.ts | 6 ++++++ 3 files changed, 15 insertions(+), 2 deletions(-) diff --git a/src/shared/api/api.ts b/src/shared/api/api.ts index 196a1c4..8eca229 100644 --- a/src/shared/api/api.ts +++ b/src/shared/api/api.ts @@ -8,7 +8,10 @@ */ import ky, { type KyInstance } from 'ky' -const API_BASE_URL = (import.meta.env.VITE_API_BASE_URL ?? '').replace(/\/$/, '') +// import.meta 를 직접 쓰지 않는 이유: orval 이 mutator 를 cjs 로 esbuild 번들하는 과정에서 +// `import.meta is not available in cjs` 경고가 떠 SDK 재생성 로그가 시끄럽다. +// 대신 vite.config.ts 의 `define` 으로 빌드 타임 치환되는 글로벌을 사용한다. +const API_BASE_URL = (__VITE_API_BASE_URL__ ?? '').replace(/\/$/, '') export const kyInstance: KyInstance = ky.create({ timeout: 10_000, @@ -18,7 +21,7 @@ export const kyInstance: KyInstance = ky.create({ hooks: { beforeRequest: [ (request) => { - const apiKey = import.meta.env.VITE_API_KEY; + const apiKey = __VITE_API_KEY__; if (apiKey) request.headers.set('x-api-key', apiKey); }, // TODO: 인증 토큰 주입 diff --git a/src/vite-env.d.ts b/src/vite-env.d.ts index 945a19a..a60880f 100644 --- a/src/vite-env.d.ts +++ b/src/vite-env.d.ts @@ -8,3 +8,7 @@ interface ImportMetaEnv { interface ImportMeta { readonly env: ImportMetaEnv; } + +// vite.config.ts `define` 로 빌드 시 치환되는 글로벌 — api 모듈에서 import.meta 회피용 +declare const __VITE_API_BASE_URL__: string; +declare const __VITE_API_KEY__: string; diff --git a/vite.config.ts b/vite.config.ts index 802f25d..517dab6 100644 --- a/vite.config.ts +++ b/vite.config.ts @@ -22,6 +22,12 @@ export default defineConfig(({ mode }) => { '@': path.resolve(__dirname, './src'), }, }, + // src/shared/api/api.ts 가 orval 의 mutator 로 cjs 번들될 때 `import.meta` 가 비어 + // 경고가 뜨던 문제를 우회. Vite 가 빌드 타임에 아래 글로벌을 실값으로 치환한다. + define: { + __VITE_API_BASE_URL__: JSON.stringify(env.VITE_API_BASE_URL ?? ''), + __VITE_API_KEY__: JSON.stringify(env.VITE_API_KEY ?? ''), + }, server: { port: 3000, host: '0.0.0.0',