fix: import node:async_hooks directly (#5198)

This commit is contained in:
Alex Yang
2025-10-09 17:35:11 -07:00
committed by GitHub
parent 3be6c8137f
commit 0717e5de80

View File

@@ -6,18 +6,10 @@ import type { AsyncLocalStorage } from "node:async_hooks";
// We only export the type here to avoid issues in environments where AsyncLocalStorage is not available. // We only export the type here to avoid issues in environments where AsyncLocalStorage is not available.
export type { AsyncLocalStorage }; export type { AsyncLocalStorage };
/**
* Dynamically import AsyncLocalStorage to avoid issues in environments where it's not available.
*
* Right now, this is primarily for Cloudflare Workers.
*
*/
let moduleName: string = "node:async_hooks";
const AsyncLocalStoragePromise: Promise<typeof AsyncLocalStorage> = import( const AsyncLocalStoragePromise: Promise<typeof AsyncLocalStorage> = import(
/* @vite-ignore */ /* @vite-ignore */
/* webpackIgnore: true */ /* webpackIgnore: true */
moduleName "node:async_hooks"
) )
.then((mod) => mod.AsyncLocalStorage) .then((mod) => mod.AsyncLocalStorage)
.catch((err) => { .catch((err) => {