Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion packages/next/errors.json
Original file line number Diff line number Diff line change
Expand Up @@ -848,5 +848,7 @@
"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",
"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",
"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": "metadataBase is not a valid URL: %s"
"850": "metadataBase is not a valid URL: %s",
"851": "Pass either `webpack` or `turbopack`, not both.",
"852": "Only custom servers can pass `webpack`, `turbo`, or `turbopack`."
}
41 changes: 31 additions & 10 deletions packages/next/src/server/next.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,15 @@ export type NextServerOptions = Omit<
> &
Partial<Pick<ServerOptions | DevServerOptions, 'conf'>>

export type NextBundlerOptions = {
/** @deprecated Use `turbopack` instead */
turbo?: boolean
/** Selects Turbopack as the bundler */
turbopack?: boolean
/** Selects Webpack as the bundler */
webpack?: boolean
}

export type RequestHandler = (
req: IncomingMessage,
res: ServerResponse,
Expand Down Expand Up @@ -531,18 +540,30 @@ class NextCustomServer implements NextWrapperServer {

// This file is used for when users run `require('next')`
function createServer(
options: NextServerOptions & {
turbo?: boolean
turbopack?: boolean
}
options: NextServerOptions & NextBundlerOptions
): NextWrapperServer {
if (
options &&
(options.turbo || options.turbopack || process.env.IS_TURBOPACK_TEST)
) {
// Configure TURBOPACK if it isn't already set
process.env.TURBOPACK ??= '1'
// next sets customServer to false when calling this function, in that case we don't want to modify the environment variables
const isCustomServer = options?.customServer ?? true
if (isCustomServer) {
const selectTurbopack =
options &&
(options.turbo || options.turbopack || process.env.IS_TURBOPACK_TEST)
const selectWebpack =
options && (options.webpack || process.env.IS_WEBPACK_TEST)
if (selectTurbopack && selectWebpack) {
throw new Error('Pass either `webpack` or `turbopack`, not both.')
}
if (selectTurbopack || !selectWebpack) {
process.env.TURBOPACK ??= selectTurbopack ? '1' : 'auto'
}
} else {
if (options && (options.webpack || options.turbo || options.turbopack)) {
throw new Error(
'Only custom servers can pass `webpack`, `turbo`, or `turbopack`.'
)
}
}

// The package is used as a TypeScript plugin.
if (
options &&
Expand Down
Loading