Skip to content

Commit 264fef1

Browse files
committed
set the bunlder props from the next servers
1 parent 6d318d6 commit 264fef1

File tree

5 files changed

+26
-2
lines changed

5 files changed

+26
-2
lines changed

packages/next/errors.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -847,5 +847,6 @@
847847
"846": "Route %s used \\`cookies()\\` inside a function cached with \\`unstable_cache()\\`. Accessing Dynamic data sources inside a cache scope is not supported. If you need this data inside a cached function use \\`cookies()\\` outside of the cached function and pass the required dynamic data in as an argument. See more info here: https://nextjs.org/docs/app/api-reference/functions/unstable_cache",
848848
"847": "Route %s with \\`dynamic = \"error\"\\` couldn't be rendered statically because it used \\`connection()\\`. See more info here: https://nextjs.org/docs/app/building-your-application/rendering/static-and-dynamic#dynamic-rendering",
849849
"848": "%sused %s. \\`searchParams\\` is a Promise and must be unwrapped with \\`await\\` or \\`React.use()\\` before accessing its properties. Learn more: https://nextjs.org/docs/messages/sync-dynamic-apis",
850-
"849": "Route %s with \\`dynamic = \"error\"\\` couldn't be rendered statically because it used \\`cookies()\\`. See more info here: https://nextjs.org/docs/app/building-your-application/rendering/static-and-dynamic#dynamic-rendering"
850+
"849": "Route %s with \\`dynamic = \"error\"\\` couldn't be rendered statically because it used \\`cookies()\\`. See more info here: https://nextjs.org/docs/app/building-your-application/rendering/static-and-dynamic#dynamic-rendering",
851+
"850": "Pass either `webpack` or `turbopack`, not both."
851852
}

packages/next/src/server/lib/render-server.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,8 @@ async function initializeImpl(opts: {
9090
bundlerService: DevBundlerService | undefined
9191
startServerSpan: Span | undefined
9292
quiet?: boolean
93+
turbopack?: boolean
94+
webpack?: boolean
9395
onDevServerCleanup: ((listener: () => Promise<void>) => void) | undefined
9496
}): Promise<ServerInitResult> {
9597
const type = process.env.__NEXT_PRIVATE_RENDER_WORKER

packages/next/src/server/lib/router-server.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,8 @@ export async function initialize(opts: {
9191
experimentalHttpsServer?: boolean
9292
startServerSpan?: Span
9393
quiet?: boolean
94+
turbopack?: boolean
95+
webpack?: boolean
9496
}): Promise<ServerInitResult> {
9597
if (!process.env.NODE_ENV) {
9698
// @ts-ignore not readonly
@@ -699,6 +701,8 @@ export async function initialize(opts: {
699701
experimentalHttpsServer: !!opts.experimentalHttpsServer,
700702
bundlerService: devBundlerService,
701703
startServerSpan: opts.startServerSpan,
704+
turbopack: opts.turbopack,
705+
webpack: opts.webpack,
702706
quiet: opts.quiet,
703707
onDevServerCleanup: opts.onDevServerCleanup,
704708
}

packages/next/src/server/lib/start-server.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,8 @@ export async function getRequestHandlers({
140140
keepAliveTimeout,
141141
experimentalHttpsServer,
142142
quiet,
143+
turbopack,
144+
webpack,
143145
}: {
144146
dir: string
145147
port: number
@@ -151,6 +153,8 @@ export async function getRequestHandlers({
151153
keepAliveTimeout?: number
152154
experimentalHttpsServer?: boolean
153155
quiet?: boolean
156+
turbopack?: boolean
157+
webpack?: boolean
154158
}): ReturnType<typeof initialize> {
155159
return initialize({
156160
dir,
@@ -164,6 +168,8 @@ export async function getRequestHandlers({
164168
experimentalHttpsServer,
165169
startServerSpan,
166170
quiet,
171+
turbopack,
172+
webpack,
167173
})
168174
}
169175

@@ -440,6 +446,9 @@ export async function startServer(
440446
minimalMode,
441447
keepAliveTimeout,
442448
experimentalHttpsServer: !!selfSignedCertificate,
449+
// Explicitly pass the bundler flag down so it doesn't override the environment variable.
450+
turbopack: process.env.TURBOPACK ? true : undefined,
451+
webpack: process.env.TURBOPACK ? undefined : true,
443452
})
444453
requestHandler = initResult.requestHandler
445454
upgradeHandler = initResult.upgradeHandler

packages/next/src/server/next.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -534,13 +534,21 @@ function createServer(
534534
options: NextServerOptions & {
535535
turbo?: boolean
536536
turbopack?: boolean
537+
webpack?: boolean
537538
}
538539
): NextWrapperServer {
539540
if (
540541
options &&
541542
(options.turbo || options.turbopack || process.env.IS_TURBOPACK_TEST)
542543
) {
543-
process.env.TURBOPACK = '1'
544+
if (options.webpack) {
545+
throw new Error('Pass either `webpack` or `turbopack`, not both.')
546+
}
547+
process.env.TURBOPACK ??= '1'
548+
} else if (!options?.webpack) {
549+
// If no options are set we default to turbopack
550+
// If TURBOPACK was already set we preserve it.
551+
process.env.TURBOPACK ??= 'auto'
544552
}
545553
// The package is used as a TypeScript plugin.
546554
if (

0 commit comments

Comments
 (0)