Skip to content

Commit 1d685d4

Browse files
authored
Turbopack build: Replace process.env.TURBOPACK usage (#77783)
Follow-up of #77762 as that was having too many conflicts as a similar change landed last night. <!-- Thanks for opening a PR! Your contribution is much appreciated. To make sure your PR is handled as smoothly as possible we request that you follow the checklist sections below. Choose the right checklist for the change(s) that you're making: ## For Contributors ### Improving Documentation - Run `pnpm prettier-fix` to fix formatting issues before opening the PR. - Read the Docs Contribution Guide to ensure your contribution follows the docs guidelines: https://nextjs.org/docs/community/contribution-guide ### Adding or Updating Examples - The "examples guidelines" are followed from our contributing doc https://github.com/vercel/next.js/blob/canary/contributing/examples/adding-examples.md - Make sure the linting passes by running `pnpm build && pnpm lint`. See https://github.com/vercel/next.js/blob/canary/contributing/repository/linting.md ### Fixing a bug - Related issues linked using `fixes #number` - Tests added. See: https://github.com/vercel/next.js/blob/canary/contributing/core/testing.md#writing-tests-for-nextjs - Errors have a helpful link attached, see https://github.com/vercel/next.js/blob/canary/contributing.md ### Adding a feature - Implements an existing feature request or RFC. Make sure the feature request has been accepted for implementation before opening a PR. (A discussion must be opened, see https://github.com/vercel/next.js/discussions/new?category=ideas) - Related issues/discussions are linked using `fixes #number` - e2e tests added (https://github.com/vercel/next.js/blob/canary/contributing/core/testing.md#writing-tests-for-nextjs) - Documentation added - Telemetry added. In case of a feature if it's used or not. - Errors have a helpful link attached, see https://github.com/vercel/next.js/blob/canary/contributing.md ## For Maintainers - Minimal description (aim for explaining to someone not on the team to understand the PR) - When linking to a Slack thread, you might want to share details of the conclusion - Link both the Linear (Fixes NEXT-xxx) and the GitHub issues - Add review comments if necessary to explain to the reviewer the logic behind a change ### What? ### Why? ### How? Closes NEXT- Fixes # -->
1 parent 6f56b5f commit 1d685d4

File tree

9 files changed

+1
-60
lines changed

9 files changed

+1
-60
lines changed

packages/next/next-runtime.webpack-config.js

+1
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,7 @@ 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),
232233
'process.env.TURBOPACK': JSON.stringify(turbo),
233234
}),
234235
!!process.env.ANALYZE &&

packages/next/src/build/index.ts

-1
Original file line numberDiff line numberDiff line change
@@ -2275,7 +2275,6 @@ 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,
22792278
},
22802279
},
22812280
appDir: dir,

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

-10
Original file line numberDiff line numberDiff line change
@@ -33,16 +33,6 @@ 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-
4636
await startServer({
4737
dir,
4838
isDev: false,

packages/next/src/server/next-server.ts

-14
Original file line numberDiff line numberDiff line change
@@ -192,20 +192,6 @@ 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-
209195
/**
210196
* This sets environment variable to be used at the time of SSR by head.tsx.
211197
* Using this from process.env allows targeting SSR by calling

packages/next/src/server/next.ts

-3
Original file line numberDiff line numberDiff line change
@@ -240,9 +240,6 @@ 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
246243
} catch (_) {
247244
// if distDir is customized we don't know until we
248245
// load the config so fallback to loading the config

test/production/app-dir/turbopack-build-marker/app/layout.tsx

-8
This file was deleted.

test/production/app-dir/turbopack-build-marker/app/page.tsx

-3
This file was deleted.

test/production/app-dir/turbopack-build-marker/next.config.js

-6
This file was deleted.

test/production/app-dir/turbopack-build-marker/turbopack-build-marker.test.ts

-15
This file was deleted.

0 commit comments

Comments
 (0)