Skip to content

Commit 8bb592e

Browse files
committed
fix: add buffer require shim
1 parent 5ce2cd9 commit 8bb592e

File tree

1 file changed

+10
-0
lines changed
  • packages/runtime/src/templates/edge

1 file changed

+10
-0
lines changed

packages/runtime/src/templates/edge/shims.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// deno-lint-ignore-file no-var prefer-const no-unused-vars no-explicit-any
33
import { decode as _base64Decode } from 'https://deno.land/std@0.175.0/encoding/base64.ts'
44
import { AsyncLocalStorage as ALSCompat } from 'https://deno.land/std@0.175.0/node/async_hooks.ts'
5+
import { Buffer as BufferCompat } from 'https://deno.land/std@0.175.0/io/buffer.ts'
56

67
/**
78
* These are the shims, polyfills and other kludges to make Next.js work in standards-compliant runtime.
@@ -48,6 +49,15 @@ const fetch /* type {typeof globalThis.fetch} */ = async (url, init) => {
4849
}
4950
}
5051

52+
if (typeof require === 'undefined') {
53+
globalThis.require = (name) => {
54+
if (name === 'buffer' || name === 'node:buffer') {
55+
return { Buffer: BufferCompat }
56+
}
57+
throw new ReferenceError('require is not defined')
58+
}
59+
}
60+
5161
// Next edge runtime uses "self" as a function-scoped global-like object, but some of the older polyfills expect it to equal globalThis
5262
// See https://nextjs.org/docs/basic-features/supported-browsers-features#polyfills
5363
const self = { ...globalThis, fetch }

0 commit comments

Comments
 (0)