@@ -11,6 +11,7 @@ import { build, Plugin } from "esbuild";
1111import { patchOptionalDependencies } from "./patches/ast/optional-deps.js" ;
1212import { patchVercelOgLibrary } from "./patches/ast/patch-vercel-og-library.js" ;
1313import * as patches from "./patches/index.js" ;
14+ import fixRequire from "./patches/plugins/require.js" ;
1415import inlineRequirePagePlugin from "./patches/plugins/require-page.js" ;
1516import setWranglerExternal from "./patches/plugins/wrangler-external.js" ;
1617import { normalizePath , patchCodeWithValidations } from "./utils/index.js" ;
@@ -49,7 +50,6 @@ export async function bundleServer(buildOpts: BuildOptions): Promise<void> {
4950
5051 console . log ( `\x1b[35m⚙️ Bundling the OpenNext server...\n\x1b[0m` ) ;
5152
52- patches . patchWranglerDeps ( buildOpts ) ;
5353 await patches . updateWebpackChunksFile ( buildOpts ) ;
5454 patchVercelOgLibrary ( buildOpts ) ;
5555
@@ -70,6 +70,7 @@ export async function bundleServer(buildOpts: BuildOptions): Promise<void> {
7070 createFixRequiresESBuildPlugin ( buildOpts ) ,
7171 inlineRequirePagePlugin ( buildOpts ) ,
7272 setWranglerExternal ( ) ,
73+ fixRequire ( ) ,
7374 ] ,
7475 external : [ "./middleware/handler.mjs" , ...optionalDependencies ] ,
7576 alias : {
@@ -102,7 +103,6 @@ export async function bundleServer(buildOpts: BuildOptions): Promise<void> {
102103 "process.env.NODE_ENV" : '"production"' ,
103104 "process.env.NEXT_MINIMAL" : "true" ,
104105 } ,
105- // We need to set platform to node so that esbuild doesn't complain about the node imports
106106 platform : "node" ,
107107 banner : {
108108 js : `
@@ -168,7 +168,10 @@ globalThis.__BUILD_TIMESTAMP_MS__ = ${Date.now()};
168168/**
169169 * This function applies patches required for the code to run on workers.
170170 */
171- async function updateWorkerBundledCode ( workerOutputFile : string , buildOpts : BuildOptions ) : Promise < void > {
171+ export async function updateWorkerBundledCode (
172+ workerOutputFile : string ,
173+ buildOpts : BuildOptions
174+ ) : Promise < void > {
172175 const code = await readFile ( workerOutputFile , "utf8" ) ;
173176
174177 const patchedCode = await patchCodeWithValidations ( code , [
@@ -191,11 +194,6 @@ async function updateWorkerBundledCode(workerOutputFile: string, buildOpts: Buil
191194 // TODO: implement for cf (possibly in @opennextjs/aws)
192195 . replace ( "patchAsyncStorage();" , "//patchAsyncStorage();" ) ,
193196 ] ,
194- [
195- '`eval("require")` calls' ,
196- ( code ) => code . replaceAll ( 'eval("require")' , "require" ) ,
197- { isOptional : true } ,
198- ] ,
199197 [
200198 "`require.resolve` call" ,
201199 // workers do not support dynamic require nor require.resolve
0 commit comments