Repository navigation
fix(nextjs): retry loading the config with TURBOPACK when Next rejects a Turbopack-only option - #699
Conversation
|
Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). View this failed invocation of the CLA check for more information. For the most up to date status, view the checks section at the bottom of the pull request. |
There was a problem hiding this comment.
Code Review
This pull request introduces logic to automatically set process.env.TURBOPACK to 'auto' when loading the configuration for Next.js 16+ projects that build with Turbopack, cleaning it up afterward to prevent conflicts. It also adds corresponding unit tests. Feedback was provided to make the buildsWithTurbopack helper more robust by using semVer.coerce to handle non-strict semver strings, safely handling potentially null scripts in package.json, and ensuring only string values are evaluated.
… detecting Turbopack
…rejects a Turbopack-only option
|
Hi @abhis3, this is up to date with main and the checks are green, but GitHub still shows it as blocked. Could you approve it again or merge it when you get a chance? |
Next 16 builds with Turbopack by default.
next buildsetsTURBOPACK=autobefore it loads theconfig (
parseBundlerArgsinpackages/next/src/lib/bundler.ts), andloadConfigrejectsTurbopack-only options when
TURBOPACKis unset:The adapter calls
loadConfig(PHASE_PRODUCTION_BUILD, root)itself beforerunBuild(), and againin
validateNextConfigOverride, without that variable. So an app that sets one of these options(
turbopackRustReactCompiler,durableUseCacheEntries,useCacheStaticRootParamTracking,cssChunking: "graph") builds locally and fails every App Hosting build. Apps work around it todaywith
turbopackRustReactCompiler: Boolean(process.env.TURBOPACK).loadConfigstill loads the config the way it does today. If Next rejects it as "only supportedwith Turbopack" and
TURBOPACKwas unset, it loads once more withTURBOPACK=auto, the valuenext builduses. It removes the variable again in afinally, so it never reachesrunBuild(),where
next build --webpackwould exit with "Multiple bundler flags set". Configs that load todaynever see the variable, so webpack apps can't regress, and only Next 16+ throws this error. Thanks
to @abhis3 for suggesting this approach in review.
next-rspackstays as it is:withRspackcallsprocess.exit(1)instead of throwing whenTURBOPACKis unset, so there is nothing to retry.Testing
loadConfigunit tests inutils.spec.tsuse a stand-innextpackage whose config loaderreports the
TURBOPACKvalue it ran with. They cover a config Next accepts (loaded withoutTURBOPACK), the Turbopack-only error (retried withauto, unset afterwards), any other error(rethrown without a retry), and the Turbopack-only error when
TURBOPACKwas already set(rethrown, variable left alone).
reactCompiler+experimental.turbopackRustReactCompiler: throws the error above → loadsexperimental.cssChunking: "strict"(webpack-only): loads → loads, withoutTURBOPACKnpm run build,npm run lint(no errors) andnpm run test:unitinadapter-nextjspass. Ididn't run
test:functional(the starter is on Next 15.5, where this path is a no-op).