1
1
// @ts -check
2
- // deno-lint-ignore-file no-var prefer-const no-unused-vars no-explicit-any
2
+ // deno-lint-ignore-file prefer-const no-unused-vars
3
3
import { decode as _base64Decode } from 'https://deno.land/std@0.175.0/encoding/base64.ts'
4
- 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'
4
+ import BufferCompat from 'https://deno.land/std@0.175.0/node/buffer.ts'
5
+ import EventsCompat from 'https://deno.land/std@0.175.0/node/events.ts'
6
+ import AsyncHooksCompat from 'https://deno.land/std@0.175.0/node/async_hooks.ts'
7
+ import AssertCompat from 'https://deno.land/std@0.175.0/node/assert.ts'
8
+ import UtilCompat from 'https://deno.land/std@0.175.0/node/util.ts'
6
9
7
10
/**
8
11
* These are the shims, polyfills and other kludges to make Next.js work in standards-compliant runtime.
@@ -19,7 +22,7 @@ globalThis.EdgeRuntime = 'netlify-edge'
19
22
let _ENTRIES = { }
20
23
21
24
// Next.js expects this as a global
22
- globalThis . AsyncLocalStorage = ALSCompat
25
+ globalThis . AsyncLocalStorage = AsyncHooksCompat . AsyncLocalStorage
23
26
24
27
// Next.js uses this extension to the Headers API implemented by Cloudflare workerd
25
28
if ( ! ( 'getAll' in Headers . prototype ) ) {
@@ -49,13 +52,23 @@ const fetch /* type {typeof globalThis.fetch} */ = async (url, init) => {
49
52
}
50
53
}
51
54
52
- // Turbopack aliases "Buffer" to a module import, so we need to provide a shim for that
55
+ // Shim native modules that Vercel makes available
53
56
if ( typeof require === 'undefined' ) {
54
57
globalThis . require = ( name ) => {
55
- if ( name === 'buffer' || name === 'node:buffer' ) {
56
- return { Buffer : BufferCompat }
58
+ switch ( name . replace ( / ^ n o d e : / , '' ) ) {
59
+ case 'buffer' :
60
+ return BufferCompat
61
+ case 'events' :
62
+ return EventsCompat
63
+ case 'async_hooks' :
64
+ return AsyncHooksCompat
65
+ case 'assert' :
66
+ return AssertCompat
67
+ case 'util' :
68
+ return UtilCompat
69
+ default :
70
+ throw new ReferenceError ( `Native module not found: ${ name } ` )
57
71
}
58
- throw new ReferenceError ( 'require is not defined' )
59
72
}
60
73
}
61
74
0 commit comments