From 513a295ffe68c9723ae478317a17e433680cb754 Mon Sep 17 00:00:00 2001 From: Michal Piechowiak Date: Fri, 31 Oct 2025 18:37:51 +0100 Subject: [PATCH] fix: add Buffer shim if is not globally available, adjust process and AsyncLocalStorage shims to only be applied when not available --- edge-runtime/shim/node.js | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/edge-runtime/shim/node.js b/edge-runtime/shim/node.js index 9f3e94fe7e..9e474be504 100644 --- a/edge-runtime/shim/node.js +++ b/edge-runtime/shim/node.js @@ -1,16 +1,21 @@ // NOTE: This is a fragment of a JavaScript program that will be inlined with // a Webpack bundle. You should not import this file from anywhere in the // application. -import { AsyncLocalStorage } from 'node:async_hooks' - import { createRequire } from 'node:module' // used in dynamically generated part -import process from 'node:process' import { registerCJSModules } from '../edge-runtime/lib/cjs.ts' // used in dynamically generated part -globalThis.process = process +if (typeof process === 'undefined') { + globalThis.process = (await import('node:process')).default +} + +if (typeof AsyncLocalStorage === 'undefined') { + globalThis.AsyncLocalStorage = (await import('node:async_hooks')).AsyncLocalStorage +} -globalThis.AsyncLocalStorage = AsyncLocalStorage +if (typeof Buffer === 'undefined') { + globalThis.Buffer = (await import('node:buffer')).Buffer +} // needed for path.relative and path.resolve to work Deno.cwd = () => ''