Skip to content

Commit a4fa384

Browse files
committed
Turbopack: canary-gate production builds
This allows `next build --turbopack` to be run without `TURBOPACK_BUILD` being set, and only allows it when used with canary Next.js builds. This also accepts `next build --turbo` and `next build --experimental-turbo` for compatibility. Note: This keeps `TURBOPACK_BUILD` for test purposes. Test Plan: - `pnpm next build --turbopack examples/basic-css/` uses Turbopack to build and succeeds - Set `next`’s package.json version to `15.3.0`, build, and run `./node_modules/.bin/next build --turbopack examples/basic-css/`. Verify the canary-gate message is shown
1 parent d41d035 commit a4fa384

File tree

4 files changed

+15
-7
lines changed

4 files changed

+15
-7
lines changed

packages/next/errors.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -663,5 +663,6 @@
663663
"662": "Invariant failed to find webpack runtime chunk",
664664
"663": "Invariant: client chunk changed but failed to detect hash %s",
665665
"664": "Missing 'next-action' header.",
666-
"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+
"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",
667+
"666": "Turbopack builds are only available in canary builds of Next.js."
667668
}

packages/next/src/bin/next.ts

+2
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,8 @@ program
130130
.option('--profile', 'Enables production profiling for React.')
131131
.option('--experimental-app-only', 'Builds only App Router routes.')
132132
.addOption(new Option('--experimental-turbo').hideHelp())
133+
.addOption(new Option('--turbo').hideHelp())
134+
.addOption(new Option('--turbopack').hideHelp())
133135
.addOption(
134136
new Option(
135137
'--experimental-build-mode [mode]',

packages/next/src/build/turbopack-build/impl.ts

+5-4
Original file line numberDiff line numberDiff line change
@@ -19,16 +19,17 @@ import loadConfig from '../../server/config'
1919
import { hasCustomExportOutput } from '../../export/utils'
2020
import { Telemetry } from '../../telemetry/storage'
2121
import { setGlobal } from '../../trace'
22-
23-
const IS_TURBOPACK_BUILD = process.env.TURBOPACK && process.env.TURBOPACK_BUILD
22+
import { isStableBuild, CanaryOnlyError } from '../../shared/lib/canary-only'
2423

2524
export async function turbopackBuild(): Promise<{
2625
duration: number
2726
buildTraceContext: undefined
2827
shutdownPromise: Promise<void>
2928
}> {
30-
if (!IS_TURBOPACK_BUILD) {
31-
throw new Error("next build doesn't support turbopack yet")
29+
if (isStableBuild()) {
30+
throw new CanaryOnlyError(
31+
'Turbopack builds are only available in canary builds of Next.js.'
32+
)
3233
}
3334

3435
await validateTurboNextConfig({

packages/next/src/cli/next-build.ts

+6-2
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ export type NextBuildOptions = {
1616
profile?: boolean
1717
lint: boolean
1818
mangling: boolean
19+
turbo?: boolean
20+
turbopack?: boolean
1921
experimentalDebugMemoryUsage: boolean
2022
experimentalAppOnly?: boolean
2123
experimentalTurbo?: boolean
@@ -34,11 +36,13 @@ const nextBuild = (options: NextBuildOptions, directory?: string) => {
3436
lint,
3537
mangling,
3638
experimentalAppOnly,
37-
experimentalTurbo,
3839
experimentalBuildMode,
3940
experimentalUploadTrace,
4041
} = options
4142

43+
const useTurbopack =
44+
options.experimentalTurbo || options.turbo || options.turbopack
45+
4246
let traceUploadUrl: string | undefined
4347
if (experimentalUploadTrace && !process.env.NEXT_TRACE_UPLOAD_DISABLED) {
4448
traceUploadUrl = experimentalUploadTrace
@@ -71,7 +75,7 @@ const nextBuild = (options: NextBuildOptions, directory?: string) => {
7175
printAndExit(`> No such directory exists as the project root: ${dir}`)
7276
}
7377

74-
if (experimentalTurbo) {
78+
if (useTurbopack) {
7579
process.env.TURBOPACK = '1'
7680
}
7781

0 commit comments

Comments
 (0)