From 4e9562d5a6877d81d0862606d0cf15f7539b1ab5 Mon Sep 17 00:00:00 2001 From: yuanzhixiang Date: Fri, 7 Aug 2026 07:17:45 +0800 Subject: [PATCH] fix: getBundlerRuntime should respect buildOutputPath getBundlerRuntime resolved the Next.js server output from appPath, which is always the project root and does not follow the buildOutputPath config. Every other consumer of the Next.js build output resolves it from appBuildOutputPath. Setting buildOutputPath to anything but "." therefore failed the build with "Unable to determine Next.js runtime (webpack or turbopack)" as soon as the project root no longer contained a stale .next directory. --- .changeset/bundler-runtime-build-output-path.md | 14 ++++++++++++++ packages/open-next/src/build/helper.ts | 5 ++++- 2 files changed, 18 insertions(+), 1 deletion(-) create mode 100644 .changeset/bundler-runtime-build-output-path.md diff --git a/.changeset/bundler-runtime-build-output-path.md b/.changeset/bundler-runtime-build-output-path.md new file mode 100644 index 000000000..9d99bac0d --- /dev/null +++ b/.changeset/bundler-runtime-build-output-path.md @@ -0,0 +1,14 @@ +--- +"@opennextjs/aws": patch +--- + +Fix `getBundlerRuntime` ignoring `buildOutputPath` + +`getBundlerRuntime` looked for the Next.js server output under `appPath`, which +is always the project root and does not follow the `buildOutputPath` config. +Every other consumer of the Next.js build output (`getBuildId`, +`copyEnvFile`, `createServerBundle`, …) resolves it from `appBuildOutputPath`. + +As a result, setting `buildOutputPath` to anything other than `.` failed the +build with `Unable to determine Next.js runtime (webpack or turbopack)` as soon +as the project root no longer contained a stale `.next` directory. diff --git a/packages/open-next/src/build/helper.ts b/packages/open-next/src/build/helper.ts index a049901e2..60300f251 100644 --- a/packages/open-next/src/build/helper.ts +++ b/packages/open-next/src/build/helper.ts @@ -511,7 +511,10 @@ export function getPackagePath(options: BuildOptions) { export function getBundlerRuntime( options: BuildOptions, ): "webpack" | "turbopack" { - const dotNextServerPath = path.join(options.appPath, ".next/server"); + const dotNextServerPath = path.join( + options.appBuildOutputPath, + ".next/server", + ); if (fs.existsSync(path.join(dotNextServerPath, "webpack-runtime.js"))) { return "webpack"; }