From cdc9efebb85b30c2a7f67fa70d08eb28213834f9 Mon Sep 17 00:00:00 2001 From: Annas Date: Mon, 4 May 2026 14:18:16 +0700 Subject: [PATCH] fix(core): load native binding via createRequire in ESM --- packages/domain/core/src/native.ts | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/packages/domain/core/src/native.ts b/packages/domain/core/src/native.ts index f05b3cf..e1ec3af 100644 --- a/packages/domain/core/src/native.ts +++ b/packages/domain/core/src/native.ts @@ -7,6 +7,7 @@ import { dirname } from "node:path" import { fileURLToPath } from "node:url" +import { createRequire } from "node:module" import { resolveNativeBinary } from "@tailwind-styled/shared" const isBrowser = typeof window !== "undefined" || typeof document !== "undefined" @@ -14,9 +15,10 @@ const NATIVE_UNAVAILABLE_MESSAGE = "[tailwind-styled/core] Native binding is required but not available.\n" + "Please ensure you have run: npm run build:rust" -// require() is safe here — tsup banner injects CJS-compatible require into ESM output. -// See tsup.config.ts esbuildOptions banner for how this is set up. -const _loadNative = (path: string): unknown => require(path) +// Use createRequire to avoid direct dynamic require() usage that breaks +// strict ESM bundlers (e.g., Next.js Turbopack module evaluation). +const _require = createRequire(import.meta.url) +const _loadNative = (path: string): unknown => _require(path) // ───────────────────────────────────────────────────────────────────────────── // Type Definitions @@ -313,4 +315,4 @@ export function extractThemeFromCSS(cssContent: string): ThemeConfig { } return theme -} \ No newline at end of file +}