Skip to content

Add back Turbopack flag in required-server-files.json #77851

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

Closed
wants to merge 2 commits into from
Closed
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
1 change: 0 additions & 1 deletion packages/next/next-runtime.webpack-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 &&
Expand Down
1 change: 1 addition & 0 deletions packages/next/src/build/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
10 changes: 10 additions & 0 deletions packages/next/src/cli/next-start.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
3 changes: 3 additions & 0 deletions packages/next/src/server/next.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 8 additions & 0 deletions test/production/app-dir/turbopack-build-marker/app/layout.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { ReactNode } from 'react'
export default function Root({ children }: { children: ReactNode }) {
return (
<html>
<body>{children}</body>
</html>
)
}
3 changes: 3 additions & 0 deletions test/production/app-dir/turbopack-build-marker/app/page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export default function Page() {
return <p>hello world</p>
}
6 changes: 6 additions & 0 deletions test/production/app-dir/turbopack-build-marker/next.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
/**
* @type {import('next').NextConfig}
*/
const nextConfig = {}

module.exports = nextConfig
Original file line number Diff line number Diff line change
@@ -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)
})
})
Loading