@@ -197,12 +197,13 @@ function isLegacyNext(nextVersion: string) {
197
197
/**
198
198
* Check if the target: `server` can be used to build the app
199
199
*/
200
- function isServerTargetNext ( nextVersion : string ) : boolean {
201
- if ( nextVersion === 'canary' || nextVersion === 'latest' ) {
200
+ function isServerTargetNext ( nextVersionRange : string ) : boolean {
201
+ if ( nextVersionRange === 'canary' || nextVersionRange === 'latest' ) {
202
202
return true ;
203
203
}
204
204
205
- return semver . gte ( nextVersion , NextServerTargetVersion ) ;
205
+ // >= NextServerTargetVersion
206
+ return ! semver . gtr ( NextServerTargetVersion , nextVersionRange ) ;
206
207
}
207
208
208
209
const name = '[@vercel/next]' ;
@@ -262,9 +263,6 @@ export async function build({
262
263
const nodeVersion = await getNodeVersion ( entryPath , undefined , config , meta ) ;
263
264
const spawnOpts = getSpawnOptions ( meta , nodeVersion ) ;
264
265
265
- const isServerTarget =
266
- nextVersionRange && isServerTargetNext ( nextVersionRange ) ;
267
-
268
266
// Add Vercel build environment variables that some dependencies need
269
267
// to determine a Vercel like build environment
270
268
spawnOpts . env = {
@@ -276,15 +274,6 @@ export async function build({
276
274
INIT_CWD : entryPath ,
277
275
} ;
278
276
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
-
288
277
const nowJsonPath = await findUp ( [ 'now.json' , 'vercel.json' ] , {
289
278
cwd : entryPath ,
290
279
} ) ;
@@ -363,8 +352,9 @@ export async function build({
363
352
console . warn ( 'WARNING: You should not upload the `.next` directory.' ) ;
364
353
}
365
354
366
- const isLegacy =
367
- ! isServerTarget && nextVersionRange && isLegacyNext ( nextVersionRange ) ;
355
+ const isServerTarget =
356
+ nextVersionRange && isServerTargetNext ( nextVersionRange ) ;
357
+ const isLegacy = nextVersionRange && isLegacyNext ( nextVersionRange ) ;
368
358
debug (
369
359
`MODE: ${
370
360
isServerTarget ? 'server(less)' : isLegacy ? 'legacy' : 'serverless'
@@ -465,6 +455,15 @@ export async function build({
465
455
const env : typeof process . env = { ...spawnOpts . env } ;
466
456
env . NODE_OPTIONS = `--max_old_space_size=${ memoryToConsume } ` ;
467
457
458
+ // Next.js changed the default output folder beginning with
459
+ // 10.0.8-canary.15 from `.next/serverless` to `.next/server`.
460
+ // This is an opt-out of this behavior for older versions.
461
+ // https://github.com/dealmore/terraform-aws-next-js/issues/86
462
+ // https://github.com/vercel/next.js/pull/22731
463
+ if ( ! isServerTarget ) {
464
+ env . NEXT_PRIVATE_TARGET = 'experimental-serverless-trace' ;
465
+ }
466
+
468
467
if ( buildCommand ) {
469
468
// Add `node_modules/.bin` to PATH
470
469
const nodeBinPath = await getNodeBinPath ( { cwd : entryPath } ) ;
0 commit comments