Skip to content

Commit b8ff4c6

Browse files
committed
Revert "Turbopack build: Replace process.env.TURBOPACK usage (#77783)"
This reverts commit 1d685d4.
1 parent 89ea0d9 commit b8ff4c6

File tree

9 files changed

+60
-1
lines changed

9 files changed

+60
-1
lines changed

Diff for: packages/next/next-runtime.webpack-config.js

-1
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,6 @@ module.exports = ({ dev, turbo, bundleType, experimental, ...rest }) => {
229229
experimental ? true : false
230230
),
231231
'process.env.NEXT_RUNTIME': JSON.stringify('nodejs'),
232-
'process.turbopack': JSON.stringify(turbo),
233232
'process.env.TURBOPACK': JSON.stringify(turbo),
234233
}),
235234
!!process.env.ANALYZE &&

Diff for: packages/next/src/build/index.ts

+1
Original file line numberDiff line numberDiff line change
@@ -2275,6 +2275,7 @@ export default async function build(
22752275

22762276
// @ts-expect-error internal field TODO: fix this, should use a separate mechanism to pass the info.
22772277
isExperimentalCompile: isCompileMode,
2278+
isTurbopackBuild: isTurbopack,
22782279
},
22792280
},
22802281
appDir: dir,

Diff for: packages/next/src/cli/next-start.ts

+10
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,16 @@ const nextStart = async (options: NextStartOptions, directory?: string) => {
3333
printAndExit(getReservedPortExplanation(port), 1)
3434
}
3535

36+
const isTurbopack = Boolean(
37+
options.turbo ||
38+
options.turbopack ||
39+
// TODO: Used for Testing in Next.js CI. Rename to something better like `NEXT_TEST_TURBOPACK`.
40+
process.env.TURBOPACK
41+
)
42+
if (isTurbopack) {
43+
process.env.TURBOPACK = '1'
44+
}
45+
3646
await startServer({
3747
dir,
3848
isDev: false,

Diff for: packages/next/src/server/next-server.ts

+14
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,20 @@ export default class NextNodeServer extends BaseServer<
192192
this.isDev = isDev
193193
this.sriEnabled = Boolean(options.conf.experimental?.sri?.algorithm)
194194

195+
// @ts-expect-error internal field not publicly exposed
196+
const isTurbopackBuild = this.nextConfig.experimental?.isTurbopackBuild
197+
if (!isDev && typeof isTurbopackBuild !== 'undefined') {
198+
if (process.env.TURBOPACK && !isTurbopackBuild) {
199+
throw new Error(
200+
`Invariant: --turbopack is set but the build used Webpack`
201+
)
202+
} else if (!process.env.TURBOPACK && isTurbopackBuild) {
203+
throw new Error(
204+
`Invariant: --turbopack is not set but the build used Turbopack. Add --turbopack to "next start".`
205+
)
206+
}
207+
}
208+
195209
/**
196210
* This sets environment variable to be used at the time of SSR by head.tsx.
197211
* Using this from process.env allows targeting SSR by calling

Diff for: packages/next/src/server/next.ts

+3
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,9 @@ export class NextServer implements NextWrapperServer {
240240
// @ts-expect-error internal field
241241
config.experimental.isExperimentalCompile =
242242
serializedConfig.experimental.isExperimentalCompile
243+
// @ts-expect-error internal field
244+
config.experimental.isTurbopackBuild =
245+
serializedConfig.experimental.isTurbopackBuild
243246
} catch (_) {
244247
// if distDir is customized we don't know until we
245248
// load the config so fallback to loading the config
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import { ReactNode } from 'react'
2+
export default function Root({ children }: { children: ReactNode }) {
3+
return (
4+
<html>
5+
<body>{children}</body>
6+
</html>
7+
)
8+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export default function Page() {
2+
return <p>hello world</p>
3+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
/**
2+
* @type {import('next').NextConfig}
3+
*/
4+
const nextConfig = {}
5+
6+
module.exports = nextConfig
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import { nextTestSetup } from 'e2e-utils'
2+
describe('turbopack-build-marker', () => {
3+
const { next } = nextTestSetup({
4+
files: __dirname,
5+
})
6+
7+
it('should have Turbopack build marker', async () => {
8+
const requiredServerFilesManifest = await next.readJSON(
9+
'.next/required-server-files.json'
10+
)
11+
expect(
12+
requiredServerFilesManifest.config.experimental.isTurbopackBuild
13+
).toBe(!!process.env.TURBOPACK)
14+
})
15+
})

0 commit comments

Comments
 (0)