From 7cbabaa46655e2098baba748348e9d4cd8a060c2 Mon Sep 17 00:00:00 2001 From: Alex Yang Date: Tue, 23 Sep 2025 14:44:40 -0700 Subject: [PATCH] chore: fix async local storage import (#4857) --- packages/better-auth/src/context/transaction.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/packages/better-auth/src/context/transaction.ts b/packages/better-auth/src/context/transaction.ts index baa82a1518..781eb85718 100644 --- a/packages/better-auth/src/context/transaction.ts +++ b/packages/better-auth/src/context/transaction.ts @@ -1,4 +1,4 @@ -import { AsyncLocalStorage } from "node:async_hooks"; +import type { AsyncLocalStorage } from "node:async_hooks"; import type { Adapter } from "../types"; /** @@ -14,6 +14,9 @@ const AsyncLocalStoragePromise: Promise = import( ) .then((mod) => mod.AsyncLocalStorage) .catch((err) => { + if ("AsyncLocalStorage" in globalThis) { + return (globalThis as any).AsyncLocalStorage; + } console.warn( "[better-auth] Warning: AsyncLocalStorage is not available in this environment. Some features may not work as expected.", );