Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 10 additions & 5 deletions edge-runtime/shim/node.js
Original file line number Diff line number Diff line change
@@ -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
}
Comment on lines +8 to +10
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

process is available in deno 2, not in deno 1


if (typeof AsyncLocalStorage === 'undefined') {
globalThis.AsyncLocalStorage = (await import('node:async_hooks')).AsyncLocalStorage
}
Comment on lines +12 to +14
Copy link
Contributor Author

@pieh pieh Oct 31, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is overall not globally available - it seems like Next.js quirk to expect it to be globally defined, checked if it is available just to be in line with other shims here


globalThis.AsyncLocalStorage = AsyncLocalStorage
if (typeof Buffer === 'undefined') {
globalThis.Buffer = (await import('node:buffer')).Buffer
}
Comment on lines +16 to +18
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is fun one - Buffer is not globally defined in deno 1.39.0, 1.46.3 or 2.2.4 (from tested versions), but is available in 2.4.2


// needed for path.relative and path.resolve to work
Deno.cwd = () => ''
Loading