@@ -50,15 +50,12 @@ export async function bundleServer(buildOpts: BuildOptions, projectOpts: Project
5050 copyPackageCliFiles ( packageDistDir , buildOpts ) ;
5151
5252 const { appPath, outputDir, monorepoRoot, debug } = buildOpts ;
53- const baseManifestPath = path . join (
54- outputDir ,
55- "server-functions/default" ,
56- getPackagePath ( buildOpts ) ,
57- ".next"
58- ) ;
59- const serverFiles = path . join ( baseManifestPath , "required-server-files.json" ) ;
53+ const dotNextPath = path . join ( outputDir , "server-functions/default" , getPackagePath ( buildOpts ) , ".next" ) ;
54+ const serverFiles = path . join ( dotNextPath , "required-server-files.json" ) ;
6055 const nextConfig = JSON . parse ( fs . readFileSync ( serverFiles , "utf-8" ) ) . config ;
6156
57+ const useTurbopack = fs . existsSync ( path . join ( dotNextPath , "server/chunks/[turbopack]_runtime.js" ) ) ;
58+
6259 console . log ( `\x1b[35m⚙️ Bundling the OpenNext server...\n\x1b[0m` ) ;
6360
6461 await patchWebpackRuntime ( buildOpts ) ;
@@ -141,13 +138,12 @@ export async function bundleServer(buildOpts: BuildOptions, projectOpts: Project
141138 // Note: we need the __non_webpack_require__ variable declared as it is used by next-server:
142139 // https://github.com/vercel/next.js/blob/be0c3283/packages/next/src/server/next-server.ts#L116-L119
143140 __non_webpack_require__ : "require" ,
141+ // The 2 following defines are used to reduce the bundle size by removing unnecessary code
142+ // Next uses different precompiled renderers (i.e. `app-page.runtime.prod.js`) based on if you use `TURBOPACK` or some experimental React features
143+ ...( useTurbopack ? { } : { "process.env.TURBOPACK" : "false" } ) ,
144144 // We make sure that environment variables that Next.js expects are properly defined
145145 "process.env.NEXT_RUNTIME" : '"nodejs"' ,
146146 "process.env.NODE_ENV" : '"production"' ,
147- // The 2 following defines are used to reduce the bundle size by removing unnecessary code
148- // Next uses different precompiled renderers (i.e. `app-page.runtime.prod.js`) based on if you use `TURBOPACK` or some experimental React features
149- // Turbopack is not supported for build at the moment, so we disable it
150- "process.env.TURBOPACK" : "false" ,
151147 // This define should be safe to use for Next 14.2+, earlier versions (13.5 and less) will cause trouble
152148 "process.env.__NEXT_EXPERIMENTAL_REACT" : `${ needsExperimentalReact ( nextConfig ) } ` ,
153149 // Fix `res.validate` in Next 15.4 (together with the `route-module` patch)
0 commit comments