@@ -11,6 +11,7 @@ import { build, Plugin } from "esbuild";
11
11
import { patchOptionalDependencies } from "./patches/ast/optional-deps.js" ;
12
12
import { patchVercelOgLibrary } from "./patches/ast/patch-vercel-og-library.js" ;
13
13
import * as patches from "./patches/index.js" ;
14
+ import fixRequire from "./patches/plugins/require.js" ;
14
15
import inlineRequirePagePlugin from "./patches/plugins/require-page.js" ;
15
16
import setWranglerExternal from "./patches/plugins/wrangler-external.js" ;
16
17
import { normalizePath , patchCodeWithValidations } from "./utils/index.js" ;
@@ -49,7 +50,6 @@ export async function bundleServer(buildOpts: BuildOptions): Promise<void> {
49
50
50
51
console . log ( `\x1b[35m⚙️ Bundling the OpenNext server...\n\x1b[0m` ) ;
51
52
52
- patches . patchWranglerDeps ( buildOpts ) ;
53
53
await patches . updateWebpackChunksFile ( buildOpts ) ;
54
54
patchVercelOgLibrary ( buildOpts ) ;
55
55
@@ -70,6 +70,7 @@ export async function bundleServer(buildOpts: BuildOptions): Promise<void> {
70
70
createFixRequiresESBuildPlugin ( buildOpts ) ,
71
71
inlineRequirePagePlugin ( buildOpts ) ,
72
72
setWranglerExternal ( ) ,
73
+ fixRequire ( ) ,
73
74
] ,
74
75
external : [ "./middleware/handler.mjs" , ...optionalDependencies ] ,
75
76
alias : {
@@ -102,7 +103,6 @@ export async function bundleServer(buildOpts: BuildOptions): Promise<void> {
102
103
"process.env.NODE_ENV" : '"production"' ,
103
104
"process.env.NEXT_MINIMAL" : "true" ,
104
105
} ,
105
- // We need to set platform to node so that esbuild doesn't complain about the node imports
106
106
platform : "node" ,
107
107
banner : {
108
108
js : `
@@ -168,7 +168,10 @@ globalThis.__BUILD_TIMESTAMP_MS__ = ${Date.now()};
168
168
/**
169
169
* This function applies patches required for the code to run on workers.
170
170
*/
171
- async function updateWorkerBundledCode ( workerOutputFile : string , buildOpts : BuildOptions ) : Promise < void > {
171
+ export async function updateWorkerBundledCode (
172
+ workerOutputFile : string ,
173
+ buildOpts : BuildOptions
174
+ ) : Promise < void > {
172
175
const code = await readFile ( workerOutputFile , "utf8" ) ;
173
176
174
177
const patchedCode = await patchCodeWithValidations ( code , [
@@ -191,11 +194,6 @@ async function updateWorkerBundledCode(workerOutputFile: string, buildOpts: Buil
191
194
// TODO: implement for cf (possibly in @opennextjs/aws)
192
195
. replace ( "patchAsyncStorage();" , "//patchAsyncStorage();" ) ,
193
196
] ,
194
- [
195
- '`eval("require")` calls' ,
196
- ( code ) => code . replaceAll ( 'eval("require")' , "require" ) ,
197
- { isOptional : true } ,
198
- ] ,
199
197
[
200
198
"`require.resolve` call" ,
201
199
// workers do not support dynamic require nor require.resolve
0 commit comments