diff --git a/packages/next/next-runtime.webpack-config.js b/packages/next/next-runtime.webpack-config.js index 59c129caa0981..c868ada85b295 100644 --- a/packages/next/next-runtime.webpack-config.js +++ b/packages/next/next-runtime.webpack-config.js @@ -229,7 +229,6 @@ module.exports = ({ dev, turbo, bundleType, experimental, ...rest }) => { experimental ? true : false ), 'process.env.NEXT_RUNTIME': JSON.stringify('nodejs'), - 'process.turbopack': JSON.stringify(turbo), 'process.env.TURBOPACK': JSON.stringify(turbo), }), !!process.env.ANALYZE && diff --git a/packages/next/src/build/index.ts b/packages/next/src/build/index.ts index c0317add32e3d..cda100c05d66c 100644 --- a/packages/next/src/build/index.ts +++ b/packages/next/src/build/index.ts @@ -2275,6 +2275,7 @@ 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/cli/next-start.ts b/packages/next/src/cli/next-start.ts index c127edbdce1d2..ee606b1c1980c 100755 --- a/packages/next/src/cli/next-start.ts +++ b/packages/next/src/cli/next-start.ts @@ -33,6 +33,16 @@ 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.ts b/packages/next/src/server/next.ts index 8ff153b83a972..62df59fa569ad 100644 --- a/packages/next/src/server/next.ts +++ b/packages/next/src/server/next.ts @@ -240,6 +240,9 @@ 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 new file mode 100644 index 0000000000000..888614deda3ba --- /dev/null +++ b/test/production/app-dir/turbopack-build-marker/app/layout.tsx @@ -0,0 +1,8 @@ +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 new file mode 100644 index 0000000000000..ff7159d9149fe --- /dev/null +++ b/test/production/app-dir/turbopack-build-marker/app/page.tsx @@ -0,0 +1,3 @@ +export default function Page() { + returnhello 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 new file mode 100644 index 0000000000000..807126e4cf0bf --- /dev/null +++ b/test/production/app-dir/turbopack-build-marker/next.config.js @@ -0,0 +1,6 @@ +/** + * @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 new file mode 100644 index 0000000000000..9c5f265498426 --- /dev/null +++ b/test/production/app-dir/turbopack-build-marker/turbopack-build-marker.test.ts @@ -0,0 +1,15 @@ +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) + }) +})