Skip to content

Commit 21b9b5e

Browse files
add comment
1 parent a0a8008 commit 21b9b5e

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

packages/open-next/src/build/edge/createEdgeBundle.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,18 @@ globalThis.Buffer = Buffer;
131131
import {AsyncLocalStorage} from "node:async_hooks";
132132
globalThis.AsyncLocalStorage = AsyncLocalStorage;
133133
134+
${
135+
''
136+
/**
137+
* Next.js sets this `__import_unsupported` on `globalThis` (with `configurable: false`):
138+
* https://github.com/vercel/next.js/blob/5b7833e3/packages/next/src/server/web/globals.ts#L94-L98
139+
*
140+
* It does so in both the middleware and the main server, so if the middleware runs in the same place
141+
* as the main handler this code gets run twice triggering a runtime error.
142+
*
143+
* For this reason we need to patch `Object.defineProperty` to avoid this issue.
144+
*/
145+
}
134146
const defaultDefineProperty = Object.defineProperty;
135147
Object.defineProperty = function(o, p, a) {
136148
if(p=== '__import_unsupported' && Boolean(globalThis.__import_unsupported)) {

0 commit comments

Comments
 (0)