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 = () => ''