Skip to content

Commit 49b7393

Browse files
committed
Add NEXT_PRIVATE_TARGET when using old serverless
1 parent 05d0ab4 commit 49b7393

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

packages/runtime/src/index.ts

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,9 @@ export async function build({
262262
const nodeVersion = await getNodeVersion(entryPath, undefined, config, meta);
263263
const spawnOpts = getSpawnOptions(meta, nodeVersion);
264264

265+
const isServerTarget =
266+
nextVersionRange && isServerTargetNext(nextVersionRange);
267+
265268
// Add Vercel build environment variables that some dependencies need
266269
// to determine a Vercel like build environment
267270
spawnOpts.env = {
@@ -273,6 +276,15 @@ export async function build({
273276
INIT_CWD: entryPath,
274277
};
275278

279+
// Next.js changed the default output folder beginning with
280+
// 10.0.8-canary.15 from `.next/serverless` to `.next/server`.
281+
// This is an opt-out of this behavior for older versions.
282+
// https://github.com/dealmore/terraform-aws-next-js/issues/86
283+
// https://github.com/vercel/next.js/pull/22731
284+
if (!isServerTarget) {
285+
spawnOpts.env['NEXT_PRIVATE_TARGET'] = 'experimental-serverless-trace';
286+
}
287+
276288
const nowJsonPath = await findUp(['now.json', 'vercel.json'], {
277289
cwd: entryPath,
278290
});
@@ -351,8 +363,6 @@ export async function build({
351363
console.warn('WARNING: You should not upload the `.next` directory.');
352364
}
353365

354-
const isServerTarget =
355-
nextVersionRange && isServerTargetNext(nextVersionRange);
356366
const isLegacy =
357367
!isServerTarget && nextVersionRange && isLegacyNext(nextVersionRange);
358368
debug(

0 commit comments

Comments
 (0)