Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Turbopack: canary-gate production builds #77146

Merged
merged 1 commit into from
Mar 17, 2025
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
3 changes: 2 additions & 1 deletion packages/next/errors.json
Original file line number Diff line number Diff line change
Expand Up @@ -663,5 +663,6 @@
"662": "Invariant failed to find webpack runtime chunk",
"663": "Invariant: client chunk changed but failed to detect hash %s",
"664": "Missing 'next-action' header.",
"665": "Failed to find Server Action \"%s\". This request might be from an older or newer deployment.\\nRead more: https://nextjs.org/docs/messages/failed-to-find-server-action"
"665": "Failed to find Server Action \"%s\". This request might be from an older or newer deployment.\\nRead more: https://nextjs.org/docs/messages/failed-to-find-server-action",
"666": "Turbopack builds are only available in canary builds of Next.js."
}
2 changes: 2 additions & 0 deletions packages/next/src/bin/next.ts
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,8 @@ program
.option('--profile', 'Enables production profiling for React.')
.option('--experimental-app-only', 'Builds only App Router routes.')
.addOption(new Option('--experimental-turbo').hideHelp())
.addOption(new Option('--turbo').hideHelp())
.addOption(new Option('--turbopack').hideHelp())
.addOption(
new Option(
'--experimental-build-mode [mode]',
Expand Down
9 changes: 5 additions & 4 deletions packages/next/src/build/turbopack-build/impl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,17 @@ import loadConfig from '../../server/config'
import { hasCustomExportOutput } from '../../export/utils'
import { Telemetry } from '../../telemetry/storage'
import { setGlobal } from '../../trace'

const IS_TURBOPACK_BUILD = process.env.TURBOPACK && process.env.TURBOPACK_BUILD
import { isStableBuild, CanaryOnlyError } from '../../shared/lib/canary-only'

export async function turbopackBuild(): Promise<{
duration: number
buildTraceContext: undefined
shutdownPromise: Promise<void>
}> {
if (!IS_TURBOPACK_BUILD) {
throw new Error("next build doesn't support turbopack yet")
if (isStableBuild()) {
throw new CanaryOnlyError(
'Turbopack builds are only available in canary builds of Next.js.'
)
}

await validateTurboNextConfig({
Expand Down
8 changes: 6 additions & 2 deletions packages/next/src/cli/next-build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ export type NextBuildOptions = {
profile?: boolean
lint: boolean
mangling: boolean
turbo?: boolean
turbopack?: boolean
experimentalDebugMemoryUsage: boolean
experimentalAppOnly?: boolean
experimentalTurbo?: boolean
Expand All @@ -34,11 +36,13 @@ const nextBuild = (options: NextBuildOptions, directory?: string) => {
lint,
mangling,
experimentalAppOnly,
experimentalTurbo,
experimentalBuildMode,
experimentalUploadTrace,
} = options

const useTurbopack =
options.experimentalTurbo || options.turbo || options.turbopack

let traceUploadUrl: string | undefined
if (experimentalUploadTrace && !process.env.NEXT_TRACE_UPLOAD_DISABLED) {
traceUploadUrl = experimentalUploadTrace
Expand Down Expand Up @@ -71,7 +75,7 @@ const nextBuild = (options: NextBuildOptions, directory?: string) => {
printAndExit(`> No such directory exists as the project root: ${dir}`)
}

if (experimentalTurbo) {
if (useTurbopack) {
process.env.TURBOPACK = '1'
}

Expand Down
Loading