From f08cde7b8ad7f192c2358c5f59b8a344861d8173 Mon Sep 17 00:00:00 2001 From: Tim Neutkens Date: Thu, 3 Apr 2025 16:50:52 +0200 Subject: [PATCH 1/4] Turbopack build: Replace process.env.TURBOPACK usage --- packages/next/next-runtime.webpack-config.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/packages/next/next-runtime.webpack-config.js b/packages/next/next-runtime.webpack-config.js index c868ada85b295..7998417bbcdb4 100644 --- a/packages/next/next-runtime.webpack-config.js +++ b/packages/next/next-runtime.webpack-config.js @@ -229,7 +229,12 @@ module.exports = ({ dev, turbo, bundleType, experimental, ...rest }) => { experimental ? true : false ), 'process.env.NEXT_RUNTIME': JSON.stringify('nodejs'), - 'process.env.TURBOPACK': JSON.stringify(turbo), + ...(turbo + ? { + 'process.turbopack': JSON.stringify(turbo), + 'process.env.TURBOPACK': JSON.stringify(turbo), + } + : undefined), }), !!process.env.ANALYZE && new BundleAnalyzerPlugin({ From ae114ef2f1433ad985dc9e0540456f551dcd5901 Mon Sep 17 00:00:00 2001 From: Tim Neutkens Date: Thu, 3 Apr 2025 16:58:47 +0200 Subject: [PATCH 2/4] Remove check for TURBOPACK=1 --- packages/next/src/cli/next-start.ts | 10 ---------- packages/next/src/server/next-server.ts | 14 -------------- 2 files changed, 24 deletions(-) diff --git a/packages/next/src/cli/next-start.ts b/packages/next/src/cli/next-start.ts index ee606b1c1980c..c127edbdce1d2 100755 --- a/packages/next/src/cli/next-start.ts +++ b/packages/next/src/cli/next-start.ts @@ -33,16 +33,6 @@ const nextStart = async (options: NextStartOptions, directory?: string) => { printAndExit(getReservedPortExplanation(port), 1) } - const isTurbopack = Boolean( - options.turbo || - options.turbopack || - // TODO: Used for Testing in Next.js CI. Rename to something better like `NEXT_TEST_TURBOPACK`. - process.env.TURBOPACK - ) - if (isTurbopack) { - process.env.TURBOPACK = '1' - } - await startServer({ dir, isDev: false, diff --git a/packages/next/src/server/next-server.ts b/packages/next/src/server/next-server.ts index 3838afc4277c2..eb98fd4bc565e 100644 --- a/packages/next/src/server/next-server.ts +++ b/packages/next/src/server/next-server.ts @@ -192,20 +192,6 @@ export default class NextNodeServer extends BaseServer< this.isDev = isDev this.sriEnabled = Boolean(options.conf.experimental?.sri?.algorithm) - // @ts-expect-error internal field not publicly exposed - const isTurbopackBuild = this.nextConfig.experimental?.isTurbopackBuild - if (!isDev && typeof isTurbopackBuild !== 'undefined') { - if (process.env.TURBOPACK && !isTurbopackBuild) { - throw new Error( - `Invariant: --turbopack is set but the build used Webpack` - ) - } else if (!process.env.TURBOPACK && isTurbopackBuild) { - throw new Error( - `Invariant: --turbopack is not set but the build used Turbopack. Add --turbopack to "next start".` - ) - } - } - /** * This sets environment variable to be used at the time of SSR by head.tsx. * Using this from process.env allows targeting SSR by calling From ff5997fb15a0ed9d4f1e8ddea970c6c01398e81a Mon Sep 17 00:00:00 2001 From: Tim Neutkens Date: Thu, 3 Apr 2025 17:21:43 +0200 Subject: [PATCH 3/4] Remove isTurbopackBuild marker --- packages/next/src/build/index.ts | 1 - packages/next/src/server/next.ts | 3 --- .../app-dir/turbopack-build-marker/app/layout.tsx | 8 -------- .../app-dir/turbopack-build-marker/app/page.tsx | 3 --- .../app-dir/turbopack-build-marker/next.config.js | 6 ------ .../turbopack-build-marker.test.ts | 15 --------------- 6 files changed, 36 deletions(-) delete mode 100644 test/production/app-dir/turbopack-build-marker/app/layout.tsx delete mode 100644 test/production/app-dir/turbopack-build-marker/app/page.tsx delete mode 100644 test/production/app-dir/turbopack-build-marker/next.config.js delete mode 100644 test/production/app-dir/turbopack-build-marker/turbopack-build-marker.test.ts diff --git a/packages/next/src/build/index.ts b/packages/next/src/build/index.ts index 22253cecd98f8..886282260c8a0 100644 --- a/packages/next/src/build/index.ts +++ b/packages/next/src/build/index.ts @@ -2274,7 +2274,6 @@ export default async function build( // @ts-expect-error internal field TODO: fix this, should use a separate mechanism to pass the info. isExperimentalCompile: isCompileMode, - isTurbopackBuild: isTurbopack, }, }, appDir: dir, diff --git a/packages/next/src/server/next.ts b/packages/next/src/server/next.ts index 62df59fa569ad..8ff153b83a972 100644 --- a/packages/next/src/server/next.ts +++ b/packages/next/src/server/next.ts @@ -240,9 +240,6 @@ export class NextServer implements NextWrapperServer { // @ts-expect-error internal field config.experimental.isExperimentalCompile = serializedConfig.experimental.isExperimentalCompile - // @ts-expect-error internal field - config.experimental.isTurbopackBuild = - serializedConfig.experimental.isTurbopackBuild } catch (_) { // if distDir is customized we don't know until we // load the config so fallback to loading the config diff --git a/test/production/app-dir/turbopack-build-marker/app/layout.tsx b/test/production/app-dir/turbopack-build-marker/app/layout.tsx deleted file mode 100644 index 888614deda3ba..0000000000000 --- a/test/production/app-dir/turbopack-build-marker/app/layout.tsx +++ /dev/null @@ -1,8 +0,0 @@ -import { ReactNode } from 'react' -export default function Root({ children }: { children: ReactNode }) { - return ( - - {children} - - ) -} diff --git a/test/production/app-dir/turbopack-build-marker/app/page.tsx b/test/production/app-dir/turbopack-build-marker/app/page.tsx deleted file mode 100644 index ff7159d9149fe..0000000000000 --- a/test/production/app-dir/turbopack-build-marker/app/page.tsx +++ /dev/null @@ -1,3 +0,0 @@ -export default function Page() { - return

hello world

-} diff --git a/test/production/app-dir/turbopack-build-marker/next.config.js b/test/production/app-dir/turbopack-build-marker/next.config.js deleted file mode 100644 index 807126e4cf0bf..0000000000000 --- a/test/production/app-dir/turbopack-build-marker/next.config.js +++ /dev/null @@ -1,6 +0,0 @@ -/** - * @type {import('next').NextConfig} - */ -const nextConfig = {} - -module.exports = nextConfig diff --git a/test/production/app-dir/turbopack-build-marker/turbopack-build-marker.test.ts b/test/production/app-dir/turbopack-build-marker/turbopack-build-marker.test.ts deleted file mode 100644 index 9c5f265498426..0000000000000 --- a/test/production/app-dir/turbopack-build-marker/turbopack-build-marker.test.ts +++ /dev/null @@ -1,15 +0,0 @@ -import { nextTestSetup } from 'e2e-utils' -describe('turbopack-build-marker', () => { - const { next } = nextTestSetup({ - files: __dirname, - }) - - it('should have Turbopack build marker', async () => { - const requiredServerFilesManifest = await next.readJSON( - '.next/required-server-files.json' - ) - expect( - requiredServerFilesManifest.config.experimental.isTurbopackBuild - ).toBe(!!process.env.TURBOPACK) - }) -}) From fcbbe8ab688a150ad76b9e7c5b910754e7b28e7d Mon Sep 17 00:00:00 2001 From: Tim Neutkens Date: Thu, 3 Apr 2025 17:23:02 +0200 Subject: [PATCH 4/4] Update next-runtime.webpack-config.js --- packages/next/next-runtime.webpack-config.js | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/packages/next/next-runtime.webpack-config.js b/packages/next/next-runtime.webpack-config.js index 7998417bbcdb4..59c129caa0981 100644 --- a/packages/next/next-runtime.webpack-config.js +++ b/packages/next/next-runtime.webpack-config.js @@ -229,12 +229,8 @@ module.exports = ({ dev, turbo, bundleType, experimental, ...rest }) => { experimental ? true : false ), 'process.env.NEXT_RUNTIME': JSON.stringify('nodejs'), - ...(turbo - ? { - 'process.turbopack': JSON.stringify(turbo), - 'process.env.TURBOPACK': JSON.stringify(turbo), - } - : undefined), + 'process.turbopack': JSON.stringify(turbo), + 'process.env.TURBOPACK': JSON.stringify(turbo), }), !!process.env.ANALYZE && new BundleAnalyzerPlugin({