Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
N
next.js
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Alex
next.js
Commits
dadfaa1b
Unverified
Commit
dadfaa1b
authored
Sep 29, 2025
by
JJ Kasper
Committed by
GitHub
Sep 29, 2025
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Revert "Add a --webpack flag and default --turbopack to true (#84216)" (#84348)
parent
8586cdf1
Show whitespace changes
Inline
Side-by-side
Showing
14 changed files
with
146 additions
and
357 deletions
+146
-357
build_and_test.yml
.github/workflows/build_and_test.yml
+1
-16
package.json
bench/heavy-npm-deps/package.json
+2
-2
package.json
bench/module-cost/package.json
+4
-4
package.json
package.json
+23
-44
index.js
packages/next-rspack/index.js
+0
-8
next.ts
packages/next/src/bin/next.ts
+2
-4
index.ts
packages/next/src/build/index.ts
+24
-36
next-build.ts
packages/next/src/cli/next-build.ts
+7
-4
next-dev.ts
packages/next/src/cli/next-dev.ts
+15
-19
bundler.ts
packages/next/src/lib/bundler.ts
+0
-90
turbopack-warning.ts
packages/next/src/lib/turbopack-warning.ts
+12
-23
test-new-tests.mjs
scripts/test-new-tests.mjs
+0
-2
index.test.ts
test/development/next-config-ts/turbo/index.test.ts
+12
-14
index.test.ts
test/e2e/config-turbopack/index.test.ts
+44
-91
No files found.
.github/workflows/build_and_test.yml
View file @
dadfaa1b
...
@@ -502,7 +502,6 @@ jobs:
...
@@ -502,7 +502,6 @@ jobs:
export NEXT_TEST_MODE=start
export NEXT_TEST_MODE=start
export NEXT_TEST_WASM=true
export NEXT_TEST_WASM=true
export IS_WEBPACK_TEST=1
node run-tests.js \
node run-tests.js \
test/production/pages-dir/production/test/index.test.ts \
test/production/pages-dir/production/test/index.test.ts \
test/e2e/streaming-ssr/index.test.ts
test/e2e/streaming-ssr/index.test.ts
...
@@ -712,7 +711,7 @@ jobs:
...
@@ -712,7 +711,7 @@ jobs:
secrets
:
inherit
secrets
:
inherit
test-dev
:
# TODO: rename to include webpack
test-dev
:
name
:
test dev
name
:
test dev
needs
:
[
'
optimize-ci'
,
'
changes'
,
'
build-native'
,
'
build-next'
]
needs
:
[
'
optimize-ci'
,
'
changes'
,
'
build-native'
,
'
build-next'
]
if
:
${{ needs.optimize-ci.outputs.skip == 'false' && needs.changes.outputs.docs-only == 'false' }}
if
:
${{ needs.optimize-ci.outputs.skip == 'false' && needs.changes.outputs.docs-only == 'false' }}
...
@@ -729,7 +728,6 @@ jobs:
...
@@ -729,7 +728,6 @@ jobs:
uses
:
./.github/workflows/build_reusable.yml
uses
:
./.github/workflows/build_reusable.yml
with
:
with
:
afterBuild
:
|
afterBuild
:
|
export IS_WEBPACK_TEST=1
export NEXT_TEST_MODE=dev
export NEXT_TEST_MODE=dev
export NEXT_TEST_REACT_VERSION="${{ matrix.react }}"
export NEXT_TEST_REACT_VERSION="${{ matrix.react }}"
...
@@ -754,10 +752,8 @@ jobs:
...
@@ -754,10 +752,8 @@ jobs:
uses
:
./.github/workflows/build_reusable.yml
uses
:
./.github/workflows/build_reusable.yml
with
:
with
:
# Should this be using turbopack? a variation?
afterBuild
:
|
afterBuild
:
|
export NEXT_TEST_MODE=dev
export NEXT_TEST_MODE=dev
export IS_WEBPACK_TEST=1
node run-tests.js \
node run-tests.js \
test/e2e/app-dir/app/index.test.ts \
test/e2e/app-dir/app/index.test.ts \
...
@@ -784,7 +780,6 @@ jobs:
...
@@ -784,7 +780,6 @@ jobs:
with
:
with
:
nodeVersion
:
20.9.0
nodeVersion
:
20.9.0
afterBuild
:
|
afterBuild
:
|
export IS_WEBPACK_TEST=1
node run-tests.js \
node run-tests.js \
--concurrency 4 \
--concurrency 4 \
test/production/pages-dir/production/test/index.test.ts \
test/production/pages-dir/production/test/index.test.ts \
...
@@ -813,7 +808,6 @@ jobs:
...
@@ -813,7 +808,6 @@ jobs:
with
:
with
:
afterBuild
:
|
afterBuild
:
|
export NEXT_TEST_MODE=start
export NEXT_TEST_MODE=start
export IS_WEBPACK_TEST=1
node run-tests.js --type production \
node run-tests.js --type production \
test/e2e/app-dir/app/index.test.ts \
test/e2e/app-dir/app/index.test.ts \
...
@@ -842,7 +836,6 @@ jobs:
...
@@ -842,7 +836,6 @@ jobs:
uses
:
./.github/workflows/build_reusable.yml
uses
:
./.github/workflows/build_reusable.yml
with
:
with
:
afterBuild
:
|
afterBuild
:
|
export IS_WEBPACK_TEST=1
export NEXT_TEST_MODE=start
export NEXT_TEST_MODE=start
export NEXT_TEST_REACT_VERSION="${{ matrix.react }}"
export NEXT_TEST_REACT_VERSION="${{ matrix.react }}"
...
@@ -882,7 +875,6 @@ jobs:
...
@@ -882,7 +875,6 @@ jobs:
with
:
with
:
nodeVersion
:
20.9.0
nodeVersion
:
20.9.0
afterBuild
:
|
afterBuild
:
|
export IS_WEBPACK_TEST=1
export NEXT_TEST_REACT_VERSION="${{ matrix.react }}"
export NEXT_TEST_REACT_VERSION="${{ matrix.react }}"
node run-tests.js \
node run-tests.js \
...
@@ -904,7 +896,6 @@ jobs:
...
@@ -904,7 +896,6 @@ jobs:
# these all run without concurrency because they're heavier
# these all run without concurrency because they're heavier
export TEST_CONCURRENCY=1
export TEST_CONCURRENCY=1
export IS_WEBPACK_TEST=1
BROWSER_NAME=firefox node run-tests.js \
BROWSER_NAME=firefox node run-tests.js \
test/production/pages-dir/production/test/index.test.ts
test/production/pages-dir/production/test/index.test.ts
...
@@ -932,7 +923,6 @@ jobs:
...
@@ -932,7 +923,6 @@ jobs:
afterBuild
:
|
afterBuild
:
|
export __NEXT_EXPERIMENTAL_PPR=true
export __NEXT_EXPERIMENTAL_PPR=true
export NEXT_EXTERNAL_TESTS_FILTERS="test/ppr-tests-manifest.json"
export NEXT_EXTERNAL_TESTS_FILTERS="test/ppr-tests-manifest.json"
export IS_WEBPACK_TEST=1
node run-tests.js \
node run-tests.js \
--timings \
--timings \
...
@@ -955,7 +945,6 @@ jobs:
...
@@ -955,7 +945,6 @@ jobs:
export __NEXT_EXPERIMENTAL_PPR=true
export __NEXT_EXPERIMENTAL_PPR=true
export NEXT_EXTERNAL_TESTS_FILTERS="test/ppr-tests-manifest.json"
export NEXT_EXTERNAL_TESTS_FILTERS="test/ppr-tests-manifest.json"
export NEXT_TEST_MODE=dev
export NEXT_TEST_MODE=dev
export IS_WEBPACK_TEST=1
node run-tests.js \
node run-tests.js \
--timings \
--timings \
...
@@ -979,7 +968,6 @@ jobs:
...
@@ -979,7 +968,6 @@ jobs:
export __NEXT_EXPERIMENTAL_PPR=true
export __NEXT_EXPERIMENTAL_PPR=true
export NEXT_EXTERNAL_TESTS_FILTERS="test/ppr-tests-manifest.json"
export NEXT_EXTERNAL_TESTS_FILTERS="test/ppr-tests-manifest.json"
export NEXT_TEST_MODE=start
export NEXT_TEST_MODE=start
export IS_WEBPACK_TEST=1
node run-tests.js \
node run-tests.js \
--timings \
--timings \
...
@@ -1002,7 +990,6 @@ jobs:
...
@@ -1002,7 +990,6 @@ jobs:
export __NEXT_EXPERIMENTAL_PPR=true # for compatibility with the existing tests
export __NEXT_EXPERIMENTAL_PPR=true # for compatibility with the existing tests
export __NEXT_EXPERIMENTAL_CACHE_COMPONENTS=true
export __NEXT_EXPERIMENTAL_CACHE_COMPONENTS=true
export NEXT_EXTERNAL_TESTS_FILTERS="test/experimental-tests-manifest.json"
export NEXT_EXTERNAL_TESTS_FILTERS="test/experimental-tests-manifest.json"
export IS_WEBPACK_TEST=1
node run-tests.js \
node run-tests.js \
--timings \
--timings \
...
@@ -1027,7 +1014,6 @@ jobs:
...
@@ -1027,7 +1014,6 @@ jobs:
export NEXT_EXTERNAL_TESTS_FILTERS="test/experimental-tests-manifest.json"
export NEXT_EXTERNAL_TESTS_FILTERS="test/experimental-tests-manifest.json"
export NEXT_TEST_MODE=dev
export NEXT_TEST_MODE=dev
export __NEXT_EXPERIMENTAL_ISOLATED_DEV_BUILD=true
export __NEXT_EXPERIMENTAL_ISOLATED_DEV_BUILD=true
export IS_WEBPACK_TEST=1
node run-tests.js \
node run-tests.js \
--timings \
--timings \
...
@@ -1052,7 +1038,6 @@ jobs:
...
@@ -1052,7 +1038,6 @@ jobs:
export __NEXT_EXPERIMENTAL_CACHE_COMPONENTS=true
export __NEXT_EXPERIMENTAL_CACHE_COMPONENTS=true
export NEXT_EXTERNAL_TESTS_FILTERS="test/experimental-tests-manifest.json"
export NEXT_EXTERNAL_TESTS_FILTERS="test/experimental-tests-manifest.json"
export NEXT_TEST_MODE=start
export NEXT_TEST_MODE=start
export IS_WEBPACK_TEST=1
node run-tests.js \
node run-tests.js \
--timings \
--timings \
...
...
bench/heavy-npm-deps/package.json
View file @
dadfaa1b
...
@@ -4,9 +4,9 @@
...
@@ -4,9 +4,9 @@
"private"
:
true
,
"private"
:
true
,
"scripts"
:
{
"scripts"
:
{
"dev-turbopack"
:
"next dev --turbopack"
,
"dev-turbopack"
:
"next dev --turbopack"
,
"dev-webpack"
:
"next dev
--webpack
"
,
"dev-webpack"
:
"next dev"
,
"build-turbopack"
:
"next build --turbopack"
,
"build-turbopack"
:
"next build --turbopack"
,
"build-webpack"
:
"next build
--webpack
"
,
"build-webpack"
:
"next build"
,
"start-turbopack"
:
"next start"
,
"start-turbopack"
:
"next start"
,
"start-webpack"
:
"next start"
,
"start-webpack"
:
"next start"
,
"build-application"
:
"next build"
,
"build-application"
:
"next build"
,
...
...
bench/module-cost/package.json
View file @
dadfaa1b
...
@@ -3,10 +3,10 @@
...
@@ -3,10 +3,10 @@
"scripts"
:
{
"scripts"
:
{
"prepare-bench"
:
"node scripts/prepare-bench.mjs"
,
"prepare-bench"
:
"node scripts/prepare-bench.mjs"
,
"benchmark"
:
"node scripts/benchmark-runner.mjs"
,
"benchmark"
:
"node scripts/benchmark-runner.mjs"
,
"dev-webpack"
:
"next dev
--webpack
"
,
"dev-webpack"
:
"next dev"
,
"dev-turbopack"
:
"next dev --turbo
pack
"
,
"dev-turbopack"
:
"next dev --turbo"
,
"build-webpack"
:
"next build
--webpack
"
,
"build-webpack"
:
"next build"
,
"build-turbopack"
:
"next build --turbo
pack
"
,
"build-turbopack"
:
"next build --turbo"
,
"start"
:
"next start"
"start"
:
"next start"
},
},
"devDependencies"
:
{
"devDependencies"
:
{
...
...
package.json
View file @
dadfaa1b
...
@@ -17,49 +17,29 @@
...
@@ -17,49 +17,29 @@
"ci:publish"
:
"tsx ./scripts/release/publish-npm.ts"
,
"ci:publish"
:
"tsx ./scripts/release/publish-npm.ts"
,
"test-types"
:
"tsc"
,
"test-types"
:
"tsc"
,
"test-unit"
:
"jest test/unit/ packages/next/ packages/font"
,
"test-unit"
:
"jest test/unit/ packages/next/ packages/font"
,
"test-dev-inner"
:
"cross-env NEXT_TEST_MODE=dev pnpm testheadless"
,
"test-dev"
:
"cross-env NEXT_TEST_MODE=dev pnpm testheadless"
,
"test-dev"
:
"pnpm run test-dev-webpack"
,
"test-dev-experimental"
:
"cross-env NEXT_TEST_MODE=dev pnpm run with-experimental pnpm testheadless"
,
"test-dev-webpack"
:
"pnpm run with-webpack pnpm test-dev-inner"
,
"test-dev-rspack"
:
"pnpm run with-rspack pnpm run test-dev"
,
"test-dev-experimental-inner"
:
"pnpm run with-experimental pnpm test-dev-inner"
,
"test-dev-experimental-rspack"
:
"pnpm run with-rspack pnpm run test-dev-experimental"
,
"test-dev-experimental"
:
"pnpm run test-dev-experimental-webpack"
,
"test-dev-turbo"
:
"cross-env NEXT_TEST_MODE=dev IS_TURBOPACK_TEST=1 TURBOPACK_DEV=1 pnpm testheadless"
,
"test-dev-experimental-webpack"
:
"pnpm run with-webpack pnpm test-dev-experimental-inner"
,
"test-dev-experimental-turbo"
:
"cross-env NEXT_TEST_MODE=dev IS_TURBOPACK_TEST=1 TURBOPACK_DEV=1 pnpm run with-experimental pnpm testheadless"
,
"test-dev-rspack"
:
"pnpm run with-rspack pnpm run test-dev-inner"
,
"test-start"
:
"cross-env NEXT_TEST_MODE=start pnpm testheadless"
,
"test-dev-experimental-rspack"
:
"pnpm run with-rspack pnpm run test-dev-experimental-inner"
,
"test-start-experimental"
:
"cross-env NEXT_TEST_MODE=start pnpm run with-experimental pnpm testheadless"
,
"test-dev-turbo"
:
"cross-env IS_TURBOPACK_TEST=1 TURBOPACK_DEV=1 pnpm test-dev-inner"
,
"test-start-rspack"
:
"pnpm run with-rspack pnpm run test-start"
,
"test-dev-experimental-turbo"
:
"cross-env IS_TURBOPACK_TEST=1 TURBOPACK_DEV=1 pnpm run with-experimental pnpm test-dev-inner"
,
"test-start-experimental-rspack"
:
"pnpm run with-rspack pnpm run test-start-experimental"
,
"test-start-inner"
:
"cross-env NEXT_TEST_MODE=start pnpm testheadless"
,
"test-start-turbo"
:
"cross-env NEXT_TEST_MODE=start IS_TURBOPACK_TEST=1 TURBOPACK_BUILD=1 pnpm testheadless"
,
"test-start"
:
"pnpm run test-start-webpack"
,
"test-start-experimental-turbo"
:
"cross-env NEXT_TEST_MODE=start IS_TURBOPACK_TEST=1 TURBOPACK_BUILD=1 pnpm run with-experimental pnpm testheadless"
,
"test-start-webpack"
:
"pnpm run with-webpack pnpm run test-start-inner"
,
"test-deploy"
:
"cross-env NEXT_TEST_MODE=deploy pnpm testheadless"
,
"test-start-experimental-inner"
:
"pnpm run with-experimental pnpm test-start-inner"
,
"testonly-dev"
:
"cross-env NEXT_TEST_MODE=dev pnpm testonly"
,
"test-start-experimental"
:
"pnpm run test-start-experimental-webpack"
,
"testonly-dev-rspack"
:
"pnpm run with-rspack pnpm run testonly-dev"
,
"test-start-experimental-webpack"
:
"pnpm run with-webpack pnpm run test-start-experimental-inner"
,
"testonly-dev-turbo"
:
"cross-env NEXT_TEST_MODE=dev IS_TURBOPACK_TEST=1 TURBOPACK_DEV=1 pnpm testonly"
,
"test-start-rspack"
:
"pnpm run with-rspack pnpm run test-start-inner"
,
"testonly-start"
:
"cross-env NEXT_TEST_MODE=start pnpm testonly"
,
"test-start-experimental-rspack"
:
"pnpm run with-rspack pnpm run test-start-experimental-inner"
,
"testonly-start-rspack"
:
"pnpm run with-rspack pnpm run testonly-start"
,
"test-start-turbo"
:
"cross-env IS_TURBOPACK_TEST=1 TURBOPACK_BUILD=1 pnpm test-start-inner"
,
"testonly-start-turbo"
:
"cross-env NEXT_TEST_MODE=start IS_TURBOPACK_TEST=1 TURBOPACK_BUILD=1 pnpm testonly"
,
"test-start-experimental-turbo"
:
"cross-env IS_TURBOPACK_TEST=1 TURBOPACK_BUILD=1 pnpm run with-experimental pnpm test-start-experimental-inner"
,
"testonly-deploy"
:
"cross-env NEXT_TEST_MODE=deploy pnpm testonly"
,
"test-deploy-inner"
:
"cross-env NEXT_TEST_MODE=deploy pnpm testheadless"
,
"test"
:
"pnpm testheadless"
,
"test-deploy"
:
"pnpm run test-deploy-webpack"
,
"test-rspack"
:
"pnpm run with-rspack pnpm run test"
,
"test-deploy-webpack"
:
"pnpm run with-webpack pnpm test-deploy-inner"
,
"test-turbo"
:
"cross-env IS_TURBOPACK_TEST=1 TURBOPACK_DEV=1 TURBOPACK_BUILD=1 pnpm testheadless"
,
"test-deploy-turbo"
:
"cross-env IS_TURBOPACK_TEST=1 TURBOPACK_BUILD=1 pnpm test-deploy-inner"
,
"testonly-dev-inner"
:
"cross-env NEXT_TEST_MODE=dev pnpm testonly"
,
"testonly-dev"
:
"pnpm run testonly-dev-webpack"
,
"testonly-dev-webpack"
:
"pnpm run with-webpack pnpm run testonly-dev-inner"
,
"testonly-dev-rspack"
:
"pnpm run with-rspack pnpm run testonly-dev-inner"
,
"testonly-dev-turbo"
:
"cross-env IS_TURBOPACK_TEST=1 TURBOPACK_DEV=1 pnpm testonly-dev-inner"
,
"testonly-start-inner"
:
"cross-env NEXT_TEST_MODE=start pnpm testonly"
,
"testonly-start"
:
"pnpm run testonly-start-webpack"
,
"testonly-start-webpack"
:
"pnpm run with-webpack pnpm run testonly-start-inner"
,
"testonly-start-rspack"
:
"pnpm run with-rspack pnpm run testonly-start-inner"
,
"testonly-start-turbo"
:
"cross-env IS_TURBOPACK_TEST=1 TURBOPACK_BUILD=1 pnpm testonly-start-inner"
,
"testonly-deploy-inner"
:
"cross-env NEXT_TEST_MODE=deploy pnpm testonly"
,
"testonly-deploy"
:
"pnpm run testonly-deploy-webpack"
,
"testonly-deploy-webpack"
:
"pnpm run with-webpack pnpm run testonly-deploy-inner"
,
"testonly-deploy-turbo"
:
"cross-env IS_TURBOPACK_TEST=1 TURBOPACK_BUILD=1 pnpm testonly-deploy-inner"
,
"test-inner"
:
"pnpm testheadless"
,
"test"
:
"pnpm test-webpack"
,
"test-webpack"
:
"pnpm run with-webpack pnpm run test-inner"
,
"test-rspack"
:
"pnpm run with-rspack pnpm run test-inner"
,
"test-turbo"
:
"cross-env IS_TURBOPACK_TEST=1 TURBOPACK_DEV=1 TURBOPACK_BUILD=1 pnpm test-inner"
,
"testonly"
:
"jest --runInBand"
,
"testonly"
:
"jest --runInBand"
,
"testheadless"
:
"cross-env HEADLESS=true pnpm testonly"
,
"testheadless"
:
"cross-env HEADLESS=true pnpm testonly"
,
"genstats"
:
"cross-env LOCAL_STATS=true node .github/actions/next-stats-action/src/index.js"
,
"genstats"
:
"cross-env LOCAL_STATS=true node .github/actions/next-stats-action/src/index.js"
,
...
@@ -109,7 +89,6 @@
...
@@ -109,7 +89,6 @@
"build-storybook"
:
"turbo run build-storybook"
,
"build-storybook"
:
"turbo run build-storybook"
,
"test-storybook"
:
"turbo run test-storybook"
,
"test-storybook"
:
"turbo run test-storybook"
,
"with-rspack"
:
"cross-env NEXT_RSPACK=1 NEXT_TEST_USE_RSPACK=1"
,
"with-rspack"
:
"cross-env NEXT_RSPACK=1 NEXT_TEST_USE_RSPACK=1"
,
"with-webpack"
:
"cross-env IS_WEBPACK_TEST=1"
,
"with-experimental"
:
"cross-env __NEXT_EXPERIMENTAL_CACHE_COMPONENTS=true __NEXT_EXPERIMENTAL_PPR=true"
"with-experimental"
:
"cross-env __NEXT_EXPERIMENTAL_CACHE_COMPONENTS=true __NEXT_EXPERIMENTAL_PPR=true"
},
},
"devDependencies"
:
{
"devDependencies"
:
{
...
...
packages/next-rspack/index.js
View file @
dadfaa1b
module
.
exports
=
function
withRspack
(
config
)
{
module
.
exports
=
function
withRspack
(
config
)
{
process
.
env
.
NEXT_RSPACK
=
'true'
process
.
env
.
NEXT_RSPACK
=
'true'
process
.
env
.
RSPACK_CONFIG_VALIDATE
=
'loose-silent'
process
.
env
.
RSPACK_CONFIG_VALIDATE
=
'loose-silent'
if
(
process
.
env
.
TURBOPACK
===
'auto'
)
{
// If next has defaulted to turbopack, override it.
delete
process
.
env
.
TURBOPACK
}
else
if
(
process
.
env
.
TURBOPACK
)
{
console
.
error
(
'Cannot call withRspack and pass the --turbopack flag.'
)
console
.
error
(
'Please configure only one bundler.'
)
process
.
exit
(
1
)
}
return
config
return
config
}
}
packages/next/src/bin/next.ts
View file @
dadfaa1b
...
@@ -133,9 +133,8 @@ program
...
@@ -133,9 +133,8 @@ program
.
option
(
'--no-mangling'
,
'Disables mangling.'
)
.
option
(
'--no-mangling'
,
'Disables mangling.'
)
.
option
(
'--profile'
,
'Enables production profiling for React.'
)
.
option
(
'--profile'
,
'Enables production profiling for React.'
)
.
option
(
'--experimental-app-only'
,
'Builds only App Router routes.'
)
.
option
(
'--experimental-app-only'
,
'Builds only App Router routes.'
)
.
option
(
'--turbo'
,
'Builds using Turbopack.'
)
.
option
(
'--turbo'
,
'Starts development mode using Turbopack.'
)
.
option
(
'--turbopack'
,
'Builds using Turbopack.'
)
.
option
(
'--turbopack'
,
'Starts development mode using Turbopack.'
)
.
option
(
'--webpack'
,
'Builds using webpack.'
)
.
addOption
(
.
addOption
(
new
Option
(
new
Option
(
'--experimental-build-mode [mode]'
,
'--experimental-build-mode [mode]'
,
...
@@ -174,7 +173,6 @@ program
...
@@ -174,7 +173,6 @@ program
)
)
.
option
(
'--turbo'
,
'Starts development mode using Turbopack.'
)
.
option
(
'--turbo'
,
'Starts development mode using Turbopack.'
)
.
option
(
'--turbopack'
,
'Starts development mode using Turbopack.'
)
.
option
(
'--turbopack'
,
'Starts development mode using Turbopack.'
)
.
option
(
'--webpack'
,
'Starts development mode using webpack.'
)
.
addOption
(
.
addOption
(
new
Option
(
new
Option
(
'-p, --port <port>'
,
'-p, --port <port>'
,
...
...
packages/next/src/build/index.ts
View file @
dadfaa1b
...
@@ -83,7 +83,6 @@ import {
...
@@ -83,7 +83,6 @@ import {
UNDERSCORE_GLOBAL_ERROR_ROUTE_ENTRY
,
UNDERSCORE_GLOBAL_ERROR_ROUTE_ENTRY
,
}
from
'../shared/lib/entry-constants'
}
from
'../shared/lib/entry-constants'
import
{
isDynamicRoute
}
from
'../shared/lib/router/utils'
import
{
isDynamicRoute
}
from
'../shared/lib/router/utils'
import
{
Bundler
,
finalizeBundlerFromConfig
}
from
'../lib/bundler'
import
type
{
__ApiPreviewProps
}
from
'../server/api-utils'
import
type
{
__ApiPreviewProps
}
from
'../server/api-utils'
import
loadConfig
from
'../server/config'
import
loadConfig
from
'../server/config'
import
type
{
BuildManifest
}
from
'../server/get-page-files'
import
type
{
BuildManifest
}
from
'../server/get-page-files'
...
@@ -902,7 +901,7 @@ export default async function build(
...
@@ -902,7 +901,7 @@ export default async function build(
runLint
=
true
,
runLint
=
true
,
noMangling
=
false
,
noMangling
=
false
,
appDirOnly
=
false
,
appDirOnly
=
false
,
bundler
=
Bundler
.
Turbopack
,
isTurbopack
=
false
,
experimentalBuildMode
:
'default'
|
'compile'
|
'generate'
|
'generate-env'
,
experimentalBuildMode
:
'default'
|
'compile'
|
'generate'
|
'generate-env'
,
traceUploadUrl
:
string
|
undefined
traceUploadUrl
:
string
|
undefined
):
Promise
<
void
>
{
):
Promise
<
void
>
{
...
@@ -915,6 +914,7 @@ export default async function build(
...
@@ -915,6 +914,7 @@ export default async function build(
try
{
try
{
const
nextBuildSpan
=
trace
(
'next-build'
,
undefined
,
{
const
nextBuildSpan
=
trace
(
'next-build'
,
undefined
,
{
buildMode
:
experimentalBuildMode
,
buildMode
:
experimentalBuildMode
,
isTurboBuild
:
String
(
isTurbopack
),
version
:
process
.
env
.
__NEXT_VERSION
as
string
,
version
:
process
.
env
.
__NEXT_VERSION
as
string
,
})
})
...
@@ -949,10 +949,6 @@ export default async function build(
...
@@ -949,10 +949,6 @@ export default async function build(
)
)
loadedConfig
=
config
loadedConfig
=
config
// Reading the config can modify environment variables that influence the bundler selection.
bundler
=
finalizeBundlerFromConfig
(
bundler
)
nextBuildSpan
.
setAttribute
(
'bundler'
,
getBundlerForTelemetry
(
bundler
))
process
.
env
.
NEXT_DEPLOYMENT_ID
=
config
.
deploymentId
||
''
process
.
env
.
NEXT_DEPLOYMENT_ID
=
config
.
deploymentId
||
''
NextBuildContext
.
config
=
config
NextBuildContext
.
config
=
config
...
@@ -975,7 +971,7 @@ export default async function build(
...
@@ -975,7 +971,7 @@ export default async function build(
NextBuildContext
.
buildId
=
buildId
NextBuildContext
.
buildId
=
buildId
if
(
experimentalBuildMode
===
'generate-env'
)
{
if
(
experimentalBuildMode
===
'generate-env'
)
{
if
(
bundler
===
Bundler
.
Turbopack
)
{
if
(
is
Turbopack
)
{
Log
.
warn
(
'generate-env is not needed with turbopack'
)
Log
.
warn
(
'generate-env is not needed with turbopack'
)
process
.
exit
(
0
)
process
.
exit
(
0
)
}
}
...
@@ -1402,7 +1398,7 @@ export default async function build(
...
@@ -1402,7 +1398,7 @@ export default async function build(
})
})
// Turbopack already handles conflicting app and page routes.
// Turbopack already handles conflicting app and page routes.
if
(
bundler
!==
Bundler
.
Turbopack
)
{
if
(
!
is
Turbopack
)
{
const
numConflictingAppPaths
=
conflictingAppPagePaths
.
length
const
numConflictingAppPaths
=
conflictingAppPagePaths
.
length
if
(
mappedAppPages
&&
numConflictingAppPaths
>
0
)
{
if
(
mappedAppPages
&&
numConflictingAppPaths
>
0
)
{
Log
.
error
(
Log
.
error
(
...
@@ -1685,7 +1681,7 @@ export default async function build(
...
@@ -1685,7 +1681,7 @@ export default async function build(
let
shutdownPromise
=
Promise
.
resolve
()
let
shutdownPromise
=
Promise
.
resolve
()
if
(
!
isGenerateMode
)
{
if
(
!
isGenerateMode
)
{
if
(
bundler
===
Bundler
.
Turbopack
)
{
if
(
is
Turbopack
)
{
const
{
const
{
duration
:
compilerDuration
,
duration
:
compilerDuration
,
shutdownPromise
:
p
,
shutdownPromise
:
p
,
...
@@ -1800,7 +1796,7 @@ export default async function build(
...
@@ -1800,7 +1796,7 @@ export default async function build(
telemetry
.
record
(
telemetry
.
record
(
eventBuildCompleted
(
pagesPaths
,
{
eventBuildCompleted
(
pagesPaths
,
{
bundler
:
getBundlerForTelemetry
(
bundler
),
bundler
:
getBundlerForTelemetry
(
isTurbopack
),
durationInSeconds
,
durationInSeconds
,
totalAppPagesCount
,
totalAppPagesCount
,
})
})
...
@@ -1816,7 +1812,7 @@ export default async function build(
...
@@ -1816,7 +1812,7 @@ export default async function build(
telemetry
.
record
(
telemetry
.
record
(
eventBuildCompleted
(
pagesPaths
,
{
eventBuildCompleted
(
pagesPaths
,
{
bundler
:
getBundlerForTelemetry
(
bundler
),
bundler
:
getBundlerForTelemetry
(
isTurbopack
),
durationInSeconds
:
compilerDuration
,
durationInSeconds
:
compilerDuration
,
totalAppPagesCount
,
totalAppPagesCount
,
})
})
...
@@ -2454,10 +2450,7 @@ export default async function build(
...
@@ -2454,10 +2450,7 @@ export default async function build(
)
)
// If there's edge routes, append the edge instrumentation hook
// If there's edge routes, append the edge instrumentation hook
// Turbopack generates this chunk with a hashed name and references it in middleware-manifest.
// Turbopack generates this chunk with a hashed name and references it in middleware-manifest.
if
(
if
(
!
isTurbopack
&&
(
edgeRuntimeAppCount
||
edgeRuntimePagesCount
))
{
bundler
!==
Bundler
.
Turbopack
&&
(
edgeRuntimeAppCount
||
edgeRuntimePagesCount
)
)
{
instrumentationHookEntryFiles
.
push
(
instrumentationHookEntryFiles
.
push
(
path
.
join
(
path
.
join
(
SERVER_DIRECTORY
,
SERVER_DIRECTORY
,
...
@@ -2510,7 +2503,7 @@ export default async function build(
...
@@ -2510,7 +2503,7 @@ export default async function build(
path
.
join
(
SERVER_DIRECTORY
,
FUNCTIONS_CONFIG_MANIFEST
),
path
.
join
(
SERVER_DIRECTORY
,
FUNCTIONS_CONFIG_MANIFEST
),
path
.
join
(
SERVER_DIRECTORY
,
MIDDLEWARE_MANIFEST
),
path
.
join
(
SERVER_DIRECTORY
,
MIDDLEWARE_MANIFEST
),
path
.
join
(
SERVER_DIRECTORY
,
MIDDLEWARE_BUILD_MANIFEST
+
'.js'
),
path
.
join
(
SERVER_DIRECTORY
,
MIDDLEWARE_BUILD_MANIFEST
+
'.js'
),
...(
bundler
!==
Bundler
.
Turbopack
...(
!
is
Turbopack
?
[
?
[
path
.
join
(
path
.
join
(
SERVER_DIRECTORY
,
SERVER_DIRECTORY
,
...
@@ -2545,7 +2538,7 @@ export default async function build(
...
@@ -2545,7 +2538,7 @@ export default async function build(
),
),
]
]
:
[]),
:
[]),
...(
pagesDir
&&
bundler
!==
Bundler
.
Turbopack
...(
pagesDir
&&
!
is
Turbopack
?
[
?
[
DYNAMIC_CSS_MANIFEST
+
'.json'
,
DYNAMIC_CSS_MANIFEST
+
'.json'
,
path
.
join
(
SERVER_DIRECTORY
,
DYNAMIC_CSS_MANIFEST
+
'.js'
),
path
.
join
(
SERVER_DIRECTORY
,
DYNAMIC_CSS_MANIFEST
+
'.js'
),
...
@@ -2613,7 +2606,7 @@ export default async function build(
...
@@ -2613,7 +2606,7 @@ export default async function build(
],
],
}
}
if
(
bundler
===
Bundler
.
Turbopack
)
{
if
(
is
Turbopack
)
{
await
writeManifest
(
await
writeManifest
(
path
.
join
(
path
.
join
(
distDir
,
distDir
,
...
@@ -2629,11 +2622,7 @@ export default async function build(
...
@@ -2629,11 +2622,7 @@ export default async function build(
await
writeFunctionsConfigManifest
(
distDir
,
functionsConfigManifest
)
await
writeFunctionsConfigManifest
(
distDir
,
functionsConfigManifest
)
if
(
if
(
!
isTurbopack
&&
!
isGenerateMode
&&
!
buildTracesPromise
)
{
bundler
!==
Bundler
.
Turbopack
&&
!
isGenerateMode
&&
!
buildTracesPromise
)
{
buildTracesPromise
=
nextBuildSpan
buildTracesPromise
=
nextBuildSpan
.
traceChild
(
'collect-build-traces'
)
.
traceChild
(
'collect-build-traces'
)
.
traceAsyncFn
(()
=>
{
.
traceAsyncFn
(()
=>
{
...
@@ -2775,7 +2764,7 @@ export default async function build(
...
@@ -2775,7 +2764,7 @@ export default async function build(
// we don't need to inline for turbopack build as
// we don't need to inline for turbopack build as
// it will handle it's own caching separate of compile
// it will handle it's own caching separate of compile
if
(
isGenerateMode
&&
bundler
!==
Bundler
.
Turbopack
)
{
if
(
isGenerateMode
&&
!
is
Turbopack
)
{
Log
.
info
(
'Inlining static env ...'
)
Log
.
info
(
'Inlining static env ...'
)
await
nextBuildSpan
await
nextBuildSpan
...
@@ -4211,7 +4200,7 @@ export default async function build(
...
@@ -4211,7 +4200,7 @@ export default async function build(
if
(
telemetry
)
{
if
(
telemetry
)
{
telemetry
.
record
(
telemetry
.
record
(
eventBuildFailed
({
eventBuildFailed
({
bundler
:
getBundlerForTelemetry
(
bundler
),
bundler
:
getBundlerForTelemetry
(
isTurbopack
),
errorCode
:
getErrorCodeForTelemetry
(
e
),
errorCode
:
getErrorCodeForTelemetry
(
e
),
durationInSeconds
:
Math
.
floor
((
Date
.
now
()
-
buildStartTime
)
/
1000
),
durationInSeconds
:
Math
.
floor
((
Date
.
now
()
-
buildStartTime
)
/
1000
),
})
})
...
@@ -4232,7 +4221,7 @@ export default async function build(
...
@@ -4232,7 +4221,7 @@ export default async function build(
mode
:
'build'
,
mode
:
'build'
,
projectDir
:
dir
,
projectDir
:
dir
,
distDir
:
loadedConfig
.
distDir
,
distDir
:
loadedConfig
.
distDir
,
isTurboSession
:
bundler
===
Bundler
.
Turbopack
,
isTurboSession
:
is
Turbopack
,
sync
:
true
,
sync
:
true
,
})
})
}
}
...
@@ -4246,17 +4235,16 @@ function errorFromUnsupportedSegmentConfig(): never {
...
@@ -4246,17 +4235,16 @@ function errorFromUnsupportedSegmentConfig(): never {
process
.
exit
(
1
)
process
.
exit
(
1
)
}
}
function
getBundlerForTelemetry
(
bundler
:
Bundler
)
{
function
getBundlerForTelemetry
(
isTurbopack
:
boolean
)
{
switch
(
bundler
)
{
if
(
isTurbopack
)
{
case
Bundler
.
Turbopack
:
return
'turbopack'
return
'turbopack'
case
Bundler
.
Rspack
:
}
if
(
process
.
env
.
NEXT_RSPACK
)
{
return
'rspack'
return
'rspack'
case
Bundler
.
Webpack
:
return
'webpack'
default
:
throw
new
Error
(
`unknown bundler:
${
bundler
}
`
)
}
}
return
'webpack'
}
}
function
getErrorCodeForTelemetry
(
err
:
unknown
)
{
function
getErrorCodeForTelemetry
(
err
:
unknown
)
{
...
...
packages/next/src/cli/next-build.ts
View file @
dadfaa1b
...
@@ -10,7 +10,6 @@ import isError from '../lib/is-error'
...
@@ -10,7 +10,6 @@ import isError from '../lib/is-error'
import
{
getProjectDir
}
from
'../lib/get-project-dir'
import
{
getProjectDir
}
from
'../lib/get-project-dir'
import
{
enableMemoryDebuggingMode
}
from
'../lib/memory/startup'
import
{
enableMemoryDebuggingMode
}
from
'../lib/memory/startup'
import
{
disableMemoryDebuggingMode
}
from
'../lib/memory/shutdown'
import
{
disableMemoryDebuggingMode
}
from
'../lib/memory/shutdown'
import
{
parseBundlerArgs
}
from
'../lib/bundler'
export
type
NextBuildOptions
=
{
export
type
NextBuildOptions
=
{
debug
?:
boolean
debug
?:
boolean
...
@@ -20,7 +19,6 @@ export type NextBuildOptions = {
...
@@ -20,7 +19,6 @@ export type NextBuildOptions = {
mangling
:
boolean
mangling
:
boolean
turbo
?:
boolean
turbo
?:
boolean
turbopack
?:
boolean
turbopack
?:
boolean
webpack
?:
boolean
experimentalDebugMemoryUsage
:
boolean
experimentalDebugMemoryUsage
:
boolean
experimentalAppOnly
?:
boolean
experimentalAppOnly
?:
boolean
experimentalTurbo
?:
boolean
experimentalTurbo
?:
boolean
...
@@ -84,7 +82,12 @@ const nextBuild = (options: NextBuildOptions, directory?: string) => {
...
@@ -84,7 +82,12 @@ const nextBuild = (options: NextBuildOptions, directory?: string) => {
printAndExit
(
`> No such directory exists as the project root:
${
dir
}
`
)
printAndExit
(
`> No such directory exists as the project root:
${
dir
}
`
)
}
}
const
bundler
=
parseBundlerArgs
(
options
)
const
isTurbopack
=
Boolean
(
options
.
turbo
||
options
.
turbopack
||
process
.
env
.
IS_TURBOPACK_TEST
)
if
(
isTurbopack
)
{
process
.
env
.
TURBOPACK
=
'1'
}
return
build
(
return
build
(
dir
,
dir
,
...
@@ -94,7 +97,7 @@ const nextBuild = (options: NextBuildOptions, directory?: string) => {
...
@@ -94,7 +97,7 @@ const nextBuild = (options: NextBuildOptions, directory?: string) => {
lint
,
lint
,
!
mangling
,
!
mangling
,
experimentalAppOnly
,
experimentalAppOnly
,
bundler
,
isTurbopack
,
experimentalBuildMode
,
experimentalBuildMode
,
traceUploadUrl
traceUploadUrl
)
)
...
...
packages/next/src/cli/next-dev.ts
View file @
dadfaa1b
...
@@ -38,17 +38,11 @@ import { once } from 'node:events'
...
@@ -38,17 +38,11 @@ import { once } from 'node:events'
import
{
clearTimeout
}
from
'timers'
import
{
clearTimeout
}
from
'timers'
import
{
flushAllTraces
,
trace
}
from
'../trace'
import
{
flushAllTraces
,
trace
}
from
'../trace'
import
{
traceId
}
from
'../trace/shared'
import
{
traceId
}
from
'../trace/shared'
import
{
Bundler
,
finalizeBundlerFromConfig
,
parseBundlerArgs
,
}
from
'../lib/bundler'
export
type
NextDevOptions
=
{
export
type
NextDevOptions
=
{
disableSourceMaps
:
boolean
disableSourceMaps
:
boolean
turbo
?:
boolean
turbo
?:
boolean
turbopack
?:
boolean
turbopack
?:
boolean
webpack
?:
boolean
port
:
number
port
:
number
hostname
?:
string
hostname
?:
string
experimentalHttps
?:
boolean
experimentalHttps
?:
boolean
...
@@ -64,11 +58,11 @@ let dir: string
...
@@ -64,11 +58,11 @@ let dir: string
let
child
:
undefined
|
ChildProcess
let
child
:
undefined
|
ChildProcess
// The config in next-dev is only used to access config.distDir for telemetry and trace.
// The config in next-dev is only used to access config.distDir for telemetry and trace.
let
config
:
NextConfigComplete
let
config
:
NextConfigComplete
let
bundler
:
Bundler
let
isTurboSession
=
false
let
traceUploadUrl
:
string
let
traceUploadUrl
:
string
let
sessionStopHandled
=
false
let
sessionStopHandled
=
false
cons
t
sessionStarted
=
Date
.
now
()
le
t
sessionStarted
=
Date
.
now
()
cons
t
sessionSpan
=
trace
(
'next-dev'
)
le
t
sessionSpan
=
trace
(
'next-dev'
)
// How long should we wait for the child to cleanly exit after sending
// How long should we wait for the child to cleanly exit after sending
// SIGINT/SIGTERM to the child process before sending SIGKILL?
// SIGINT/SIGTERM to the child process before sending SIGKILL?
...
@@ -129,13 +123,11 @@ const handleSessionStop = async (signal: NodeJS.Signals | number | null) => {
...
@@ -129,13 +123,11 @@ const handleSessionStop = async (signal: NodeJS.Signals | number | null) => {
new
Telemetry
({
new
Telemetry
({
distDir
:
path
.
join
(
dir
,
config
.
distDir
),
distDir
:
path
.
join
(
dir
,
config
.
distDir
),
})
})
// Reading the config can modify environment variables that influence the bundler selection.
bundler
=
finalizeBundlerFromConfig
(
bundler
)
telemetry
.
record
(
telemetry
.
record
(
eventCliSessionStopped
({
eventCliSessionStopped
({
cliCommand
:
'dev'
,
cliCommand
:
'dev'
,
turboFlag
:
bundler
===
Bundler
.
Turbopack
,
turboFlag
:
isTurboSession
,
durationMilliseconds
:
Date
.
now
()
-
sessionStarted
,
durationMilliseconds
:
Date
.
now
()
-
sessionStarted
,
pagesDir
,
pagesDir
,
appDir
,
appDir
,
...
@@ -154,7 +146,7 @@ const handleSessionStop = async (signal: NodeJS.Signals | number | null) => {
...
@@ -154,7 +146,7 @@ const handleSessionStop = async (signal: NodeJS.Signals | number | null) => {
mode
:
'dev'
,
mode
:
'dev'
,
projectDir
:
dir
,
projectDir
:
dir
,
distDir
:
config
.
distDir
,
distDir
:
config
.
distDir
,
isTurboSession
:
bundler
===
Bundler
.
Turbopack
,
isTurboSession
,
})
})
}
}
...
@@ -176,7 +168,14 @@ const nextDev = async (
...
@@ -176,7 +168,14 @@ const nextDev = async (
portSource
:
PortSource
,
portSource
:
PortSource
,
directory
?:
string
directory
?:
string
)
=>
{
)
=>
{
bundler
=
parseBundlerArgs
(
options
)
const
isTurbopack
=
Boolean
(
options
.
turbo
||
options
.
turbopack
||
process
.
env
.
IS_TURBOPACK_TEST
)
if
(
isTurbopack
)
{
process
.
env
.
TURBOPACK
=
'1'
}
isTurboSession
=
isTurbopack
dir
=
getProjectDir
(
process
.
env
.
NEXT_PRIVATE_DEV_DIR
||
directory
)
dir
=
getProjectDir
(
process
.
env
.
NEXT_PRIVATE_DEV_DIR
||
directory
)
...
@@ -289,9 +288,7 @@ const nextDev = async (
...
@@ -289,9 +288,7 @@ const nextDev = async (
stdio
:
'inherit'
,
stdio
:
'inherit'
,
env
:
{
env
:
{
...
defaultEnv
,
...
defaultEnv
,
...(
bundler
===
Bundler
.
Turbopack
...(
isTurbopack
?
{
TURBOPACK
:
'1'
}
:
undefined
),
?
{
TURBOPACK
:
process
.
env
.
TURBOPACK
}
:
undefined
),
NEXT_PRIVATE_WORKER
:
'1'
,
NEXT_PRIVATE_WORKER
:
'1'
,
NEXT_PRIVATE_TRACE_ID
:
traceId
,
NEXT_PRIVATE_TRACE_ID
:
traceId
,
NODE_EXTRA_CA_CERTS
:
startServerOptions
.
selfSignedCertificate
NODE_EXTRA_CA_CERTS
:
startServerOptions
.
selfSignedCertificate
...
@@ -339,13 +336,12 @@ const nextDev = async (
...
@@ -339,13 +336,12 @@ const nextDev = async (
(
await
loadConfig
(
PHASE_DEVELOPMENT_SERVER
,
dir
,
{
(
await
loadConfig
(
PHASE_DEVELOPMENT_SERVER
,
dir
,
{
silent
:
true
,
silent
:
true
,
}))
}))
bundler
=
finalizeBundlerFromConfig
(
bundler
)
uploadTrace
({
uploadTrace
({
traceUploadUrl
,
traceUploadUrl
,
mode
:
'dev'
,
mode
:
'dev'
,
projectDir
:
dir
,
projectDir
:
dir
,
distDir
:
config
.
distDir
,
distDir
:
config
.
distDir
,
isTurboSession
:
bundler
===
Bundler
.
Turbopack
,
isTurboSession
,
sync
:
true
,
sync
:
true
,
})
})
}
}
...
...
packages/next/src/lib/bundler.ts
deleted
100644 → 0
View file @
8586cdf1
/// Utilties for configuring the bundler to use.
export
enum
Bundler
{
Turbopack
,
Webpack
,
Rspack
,
}
/**
* Parse the bundler arguments and potentially sets the `TURBOPACK` environment variable.
*
* NOTE: rspack is configured via next config which is chaotic so it is possible for this to be overridden later.
*
* @param options The options to parse.
* @returns The bundler that was configured
*/
export
function
parseBundlerArgs
(
options
:
{
turbo
?:
boolean
turbopack
?:
boolean
webpack
?:
boolean
}):
Bundler
{
const
bundlerFlags
=
new
Map
<
Bundler
,
string
[]
>
()
const
setBundlerFlag
=
(
bundler
:
Bundler
,
flag
:
string
)
=>
{
bundlerFlags
.
set
(
bundler
,
(
bundlerFlags
.
get
(
bundler
)
??
[]).
concat
(
flag
))
}
// What turbo flag was set? We allow multiple to be set, which is silly but not ambiguous, just pick the most relevant one.
if
(
options
.
turbopack
)
{
setBundlerFlag
(
Bundler
.
Turbopack
,
'--turbopack'
)
}
if
(
options
.
turbo
)
{
setBundlerFlag
(
Bundler
.
Turbopack
,
'--turbo'
)
}
else
if
(
process
.
env
.
TURBOPACK
)
{
// We don't really want to support this but it is trivial and not really confusing.
// If we don't support it and someone sets it, we would have inconsistent behavior
// since some parts of next would read the return value of this function and other
// parts will read the env variable.
setBundlerFlag
(
Bundler
.
Turbopack
,
'TURBOPACK'
)
}
else
if
(
process
.
env
.
IS_TURBOPACK_TEST
)
{
setBundlerFlag
(
Bundler
.
Turbopack
,
'IS_TURBOPACK_TEST'
)
}
if
(
options
.
webpack
)
{
setBundlerFlag
(
Bundler
.
Webpack
,
'--webpack'
)
}
if
(
process
.
env
.
IS_WEBPACK_TEST
)
{
setBundlerFlag
(
Bundler
.
Webpack
,
'IS_WEBPACK_TEST'
)
}
// Mostly this is set via the NextConfig but it can also be set via the command line which is
// common for testing.
if
(
process
.
env
.
NEXT_RSPACK
)
{
setBundlerFlag
(
Bundler
.
Rspack
,
'NEXT_RSPACK'
)
}
if
(
process
.
env
.
IS_RSPACK_TEST
)
{
setBundlerFlag
(
Bundler
.
Rspack
,
'NEXT_TEST_USE_RSPACK'
)
}
if
(
bundlerFlags
.
size
>
1
)
{
console
.
error
(
`Multiple bundler flags set:
${
Array
.
from
(
bundlerFlags
.
values
()).
flat
().
join
(
', '
)}
. Configure exactly one bundler.`
)
process
.
exit
(
1
)
}
// The default is turbopack when nothing is configured.
if
(
bundlerFlags
.
size
===
0
)
{
process
.
env
.
TURBOPACK
=
'auto'
return
Bundler
.
Turbopack
}
if
(
bundlerFlags
.
has
(
Bundler
.
Turbopack
))
{
// Only conditionally assign to the environment variable, preserving already set values.
// If it was set to 'auto' because no flag was set and this function is called a second time we
// would upgrade to '1' but we don't really want that.
process
.
env
.
TURBOPACK
??
=
'1'
return
Bundler
.
Turbopack
}
// Otherwise it is one of rspack or webpack. At this point there must be exactly one key in the map.
return
bundlerFlags
.
keys
().
next
().
value
!
}
/**
* Finalize the bundler based on the config.
*
* Rspack is configured via next config by setting an environment variable (yay, side effects)
* so this should only be called after parsing the config.
*/
export
function
finalizeBundlerFromConfig
(
fromOptions
:
Bundler
)
{
// Reading the next config can set NEXT_RSPACK environment variables.
if
(
process
.
env
.
NEXT_RSPACK
)
{
return
Bundler
.
Rspack
}
return
fromOptions
}
packages/next/src/lib/turbopack-warning.ts
View file @
dadfaa1b
...
@@ -47,9 +47,11 @@ const unsupportedTurbopackNextConfigOptions = [
...
@@ -47,9 +47,11 @@ const unsupportedTurbopackNextConfigOptions = [
]
]
// The following will need to be supported by `next build --turbopack`
// The following will need to be supported by `next build --turbopack`
const
unsupportedProductionSpecificTurbopackNextConfigOptions
:
string
[]
=
[]
const
unsupportedProductionSpecificTurbopackNextConfigOptions
:
string
[]
=
[
// TODO: Support disabling sourcemaps, currently they're always enabled.
// 'productionBrowserSourceMaps',
]
/** */
export
async
function
validateTurboNextConfig
({
export
async
function
validateTurboNextConfig
({
dir
,
dir
,
isDev
,
isDev
,
...
@@ -69,7 +71,7 @@ export async function validateTurboNextConfig({
...
@@ -69,7 +71,7 @@ export async function validateTurboNextConfig({
let
hasWebpackConfig
=
false
let
hasWebpackConfig
=
false
let
hasTurboConfig
=
false
let
hasTurboConfig
=
false
cons
t
unsupportedConfig
:
string
[]
=
[]
le
t
unsupportedConfig
:
string
[]
=
[]
let
rawNextConfig
:
NextConfig
=
{}
let
rawNextConfig
:
NextConfig
=
{}
const
phase
=
isDev
?
PHASE_DEVELOPMENT_SERVER
:
PHASE_PRODUCTION_BUILD
const
phase
=
isDev
?
PHASE_DEVELOPMENT_SERVER
:
PHASE_PRODUCTION_BUILD
...
@@ -122,7 +124,7 @@ export async function validateTurboNextConfig({
...
@@ -122,7 +124,7 @@ export async function validateTurboNextConfig({
const
customKeys
=
flattenKeys
(
rawNextConfig
)
const
customKeys
=
flattenKeys
(
rawNextConfig
)
cons
t
unsupportedKeys
=
isDev
le
t
unsupportedKeys
=
isDev
?
unsupportedTurbopackNextConfigOptions
?
unsupportedTurbopackNextConfigOptions
:
[
:
[
...
unsupportedTurbopackNextConfigOptions
,
...
unsupportedTurbopackNextConfigOptions
,
...
@@ -137,7 +139,7 @@ export async function validateTurboNextConfig({
...
@@ -137,7 +139,7 @@ export async function validateTurboNextConfig({
hasTurboConfig
=
true
hasTurboConfig
=
true
}
}
cons
t
isUnsupported
=
le
t
isUnsupported
=
unsupportedKeys
.
some
(
unsupportedKeys
.
some
(
(
unsupportedKey
)
=>
(
unsupportedKey
)
=>
// Either the key matches (or is a more specific subkey) of
// Either the key matches (or is a more specific subkey) of
...
@@ -160,26 +162,13 @@ export async function validateTurboNextConfig({
...
@@ -160,26 +162,13 @@ export async function validateTurboNextConfig({
Log
.
error
(
'Unexpected error occurred while checking config'
,
e
)
Log
.
error
(
'Unexpected error occurred while checking config'
,
e
)
}
}
// If the build was defaulted to Turbopack, we want to warn about possibly ignored webpack
if
(
hasWebpackConfig
&&
!
hasTurboConfig
)
{
// configuration. Otherwise the user explicitly picked turbopack and thus we expect that
Log
.
warn
(
// they have configured it correctly.
`Webpack is configured while Turbopack is not, which may cause problems.`
if
(
process
.
env
.
TURBOPACK
===
'auto'
&&
hasWebpackConfig
&&
!
hasTurboConfig
)
{
const
logMethod
=
isDev
?
Log
.
warn
:
Log
.
error
// In a production build with auto-detected Turbopack, we want to fail the build.
logMethod
(
`Webpack is configured while Turbopack is not. This may be a mistake.`
)
logMethod
(
`To configure Turbopack, see:\n https://nextjs.org/docs/app/api-reference/next-config-js/turbopack`
)
)
logMethod
(
Log
.
warn
(
`
TIP: Silence this
${
isDev
?
'warning'
:
'error'
}
by passing the --turbopack or --webpack flag explicitly.
`
`
See instructions if you need to configure Turbopack:\n https://nextjs.org/docs/app/api-reference/next-config-js/turbopack\n
`
)
)
// For production builds we want to simply fail to prevent accidental misconfiguration.
if
(
!
isDev
)
{
process
.
exit
(
1
)
}
}
}
if
(
unsupportedConfig
.
length
)
{
if
(
unsupportedConfig
.
length
)
{
...
...
scripts/test-new-tests.mjs
View file @
dadfaa1b
...
@@ -153,7 +153,6 @@ async function main() {
...
@@ -153,7 +153,6 @@ async function main() {
NEXT_EXTERNAL_TESTS_FILTERS
,
NEXT_EXTERNAL_TESTS_FILTERS
,
NEXT_TEST_MODE
:
testMode
,
NEXT_TEST_MODE
:
testMode
,
NEXT_TEST_VERSION
:
nextTestVersion
,
NEXT_TEST_VERSION
:
nextTestVersion
,
IS_WEBPACK_TEST
:
'1'
,
},
},
})
})
}
}
...
@@ -171,7 +170,6 @@ async function main() {
...
@@ -171,7 +170,6 @@ async function main() {
NEXT_TEST_VERSION
:
nextTestVersion
,
NEXT_TEST_VERSION
:
nextTestVersion
,
IS_TURBOPACK_TEST
:
'1'
,
IS_TURBOPACK_TEST
:
'1'
,
TURBOPACK_BUILD
:
testMode
===
'start'
?
'1'
:
undefined
,
TURBOPACK_BUILD
:
testMode
===
'start'
?
'1'
:
undefined
,
TURBOPACK_DEV
:
testMode
===
'dev'
?
'1'
:
undefined
,
},
},
})
})
}
}
...
...
test/development/next-config-ts/turbo/index.test.ts
View file @
dadfaa1b
import
{
nextTestSetup
}
from
'e2e-utils'
import
{
nextTestSetup
}
from
'e2e-utils'
;(
process
.
env
.
IS_TURBOPACK_TEST
?
describe
:
describe
.
skip
)(
'next-config-ts - turbopack'
,
describe
(
'next-config-ts - turbopack'
,
()
=>
{
()
=>
{
const
{
next
}
=
nextTestSetup
({
const
{
next
}
=
nextTestSetup
({
files
:
__dirname
,
files
:
__dirname
,
// explicitly ensure that turbopack is used
// explicitly ensure that turbopack is used
startCommand
:
'pnpm next dev --turbopack
'
,
startCommand
:
'pnpm next dev --turbo
'
,
})
})
it
(
'should work with Turbopack'
,
async
()
=>
{
it
(
'should work with Turbopack'
,
async
()
=>
{
const
$
=
await
next
.
render$
(
'/'
)
const
$
=
await
next
.
render$
(
'/'
)
expect
(
$
(
'p'
).
text
()).
toBe
(
'foo'
)
expect
(
$
(
'p'
).
text
()).
toBe
(
'foo'
)
})
})
}
})
)
test/e2e/config-turbopack/index.test.ts
View file @
dadfaa1b
...
@@ -5,37 +5,15 @@ const WARNING_MESSAGE = 'Webpack is configured while Turbopack is not'
...
@@ -5,37 +5,15 @@ const WARNING_MESSAGE = 'Webpack is configured while Turbopack is not'
const
itif
=
(
condition
:
boolean
)
=>
(
condition
?
it
:
it
.
skip
)
const
itif
=
(
condition
:
boolean
)
=>
(
condition
?
it
:
it
.
skip
)
const
page
=
{
'app/page.js'
:
`
export default function Page() {
return <p>hello world</p>
}
`
,
}
const
TURBOPACK_FLAG
=
process
.
env
.
TURBOPACK
describe
(
'config-turbopack'
,
()
=>
{
describe
(
'config-turbopack'
,
()
=>
{
describe
(
'when turbopack is auto selected'
,
()
=>
{
if
(
process
.
env
.
IS_TURBOPACK_TEST
)
{
beforeAll
(()
=>
{
// This is hacky since it isn't a public API, but it's the only way to test this.
// If next started ignoring IS_TURBOPACK_TEST we could possibly change nextTestSetup to not set the turbopack flag.
process
.
env
.
TURBOPACK
=
'auto'
})
afterAll
(()
=>
{
if
(
TURBOPACK_FLAG
)
{
process
.
env
.
TURBOPACK
=
TURBOPACK_FLAG
}
else
{
delete
process
.
env
.
TURBOPACK
}
})
}
describe
(
'when webpack is configured but Turbopack is not'
,
()
=>
{
describe
(
'when webpack is configured but Turbopack is not'
,
()
=>
{
const
{
next
,
isTurbopack
,
isNextDev
,
isNextStart
}
=
nextTestSetup
({
const
{
next
,
isTurbopack
}
=
nextTestSetup
({
skipStart
:
Boolean
(
process
.
env
.
TURBOPACK_BUILD
),
turbo
:
false
,
files
:
{
files
:
{
...
page
,
'app/page.js'
:
`
export default function Page() {
return <p>hello world</p>
}
`
,
'next.config.js'
:
`
'next.config.js'
:
`
module.exports = {
module.exports = {
webpack: (config) => {
webpack: (config) => {
...
@@ -46,48 +24,20 @@ describe('config-turbopack', () => {
...
@@ -46,48 +24,20 @@ describe('config-turbopack', () => {
},
},
})
})
itif
(
isTurbopack
&&
isNextDev
)(
'warns'
,
async
()
=>
{
itif
(
isTurbopack
)(
'warns'
,
async
()
=>
{
if
(
next
)
await
next
.
render
(
'/'
)
if
(
next
)
await
next
.
render
(
'/'
)
expect
(
next
.
cliOutput
).
toContain
(
WARNING_MESSAGE
)
expect
(
next
.
cliOutput
).
toContain
(
WARNING_MESSAGE
)
})
})
itif
(
isTurbopack
&&
isNextStart
)(
'errors'
,
async
()
=>
{
const
{
exitCode
,
cliOutput
}
=
await
next
.
build
()
expect
(
exitCode
).
toBe
(
1
)
expect
(
cliOutput
).
toContain
(
WARNING_MESSAGE
)
})
})
// no warn cases work when auto selected too
noWarnCases
()
})
})
describe
(
'when turbopack is explicitly configured'
,
()
=>
{
describe
(
'when webpack is configured and config.turbopack is set'
,
()
=>
{
describe
(
'when webpack is configured but Turbopack is not'
,
()
=>
{
const
{
next
,
isTurbopack
}
=
nextTestSetup
({
const
{
next
,
isTurbopack
}
=
nextTestSetup
({
files
:
{
files
:
{
...
page
,
'app/page.js'
:
`
'next.config.js'
:
`
export default function Page() {
module.exports = {
return <p>hello world</p>
webpack: (config) => {
return config
},
}
}
`
,
`
,
},
})
itif
(
isTurbopack
)(
'does not warn'
,
async
()
=>
{
if
(
next
)
await
next
.
render
(
'/'
)
expect
(
next
.
cliOutput
).
not
.
toContain
(
WARNING_MESSAGE
)
})
})
noWarnCases
()
})
/// These other cases don't warn because --turbopack is explicitly selected
function
noWarnCases
()
{
describe
(
'when webpack is configured and config.turbopack is set'
,
()
=>
{
const
{
next
,
isTurbopack
}
=
nextTestSetup
({
files
:
{
...
page
,
'next.config.js'
:
`
'next.config.js'
:
`
module.exports = {
module.exports = {
turbopack: {
turbopack: {
...
@@ -114,7 +64,11 @@ describe('config-turbopack', () => {
...
@@ -114,7 +64,11 @@ describe('config-turbopack', () => {
describe
(
'when webpack is configured and config.experimental.turbo is set'
,
()
=>
{
describe
(
'when webpack is configured and config.experimental.turbo is set'
,
()
=>
{
const
{
next
,
isTurbopack
}
=
nextTestSetup
({
const
{
next
,
isTurbopack
}
=
nextTestSetup
({
files
:
{
files
:
{
...
page
,
'app/page.js'
:
`
export default function Page() {
return <p>hello world</p>
}
`
,
'next.config.js'
:
`
'next.config.js'
:
`
module.exports = {
module.exports = {
experimental: {
experimental: {
...
@@ -139,5 +93,4 @@ describe('config-turbopack', () => {
...
@@ -139,5 +93,4 @@ describe('config-turbopack', () => {
expect
(
next
.
cliOutput
).
not
.
toContain
(
WARNING_MESSAGE
)
expect
(
next
.
cliOutput
).
not
.
toContain
(
WARNING_MESSAGE
)
})
})
})
})
}
})
})
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment