···5050 copyPackageCliFiles(packageDistDir, buildOpts);
51515252 const { appPath, outputDir, monorepoRoot, debug } = buildOpts;
5353- const baseManifestPath = path.join(
5454- outputDir,
5555- "server-functions/default",
5656- getPackagePath(buildOpts),
5757- ".next"
5858- );
5959- const serverFiles = path.join(baseManifestPath, "required-server-files.json");
5353+ const dotNextPath = path.join(outputDir, "server-functions/default", getPackagePath(buildOpts), ".next");
5454+ const serverFiles = path.join(dotNextPath, "required-server-files.json");
6055 const nextConfig = JSON.parse(fs.readFileSync(serverFiles, "utf-8")).config;
5656+5757+ const useTurbopack = fs.existsSync(path.join(dotNextPath, "server/chunks/[turbopack]_runtime.js"));
61586259 console.log(`\x1b[35m⚙️ Bundling the OpenNext server...\n\x1b[0m`);
6360···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",
141141+ // The 2 following defines are used to reduce the bundle size by removing unnecessary code
142142+ // Next uses different precompiled renderers (i.e. `app-page.runtime.prod.js`) based on if you use `TURBOPACK` or some experimental React features
143143+ ...(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"',
147147- // The 2 following defines are used to reduce the bundle size by removing unnecessary code
148148- // Next uses different precompiled renderers (i.e. `app-page.runtime.prod.js`) based on if you use `TURBOPACK` or some experimental React features
149149- // Turbopack is not supported for build at the moment, so we disable it
150150- "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)