You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Keep build-only config (turbopack.rules, webpack) out of required-server-files and standalone server.js
#102045
Keep build-only configuration (turbopack, webpack) out of the deployed output (.next/required-server-files.json, .next/required-server-files.js, and the standalone server.js).
Let Turbopack loader plugins pass options through turbopack.rules without those options being shipped to production servers.
Make this the default, without requiring experimental.runtimeServerDeploymentId.
Non-Goals
Changing how runtime config keys (images, i18n, basePath, experimental.serverActions, …) are written.
Changing anything in development.
Background
next build writes the resolved next.config into .next/required-server-files.json and its .js twin. writeStandaloneDirectory then embeds the same object into the standalone server.js as const nextConfig = …. This is how next start and standalone servers get their config without evaluating next.config again.
The object comes from getNextConfigRuntime(config) in packages/next/src/server/config-shared.ts. That function already reduces the config to the keys the server needs at runtime, and turbopack and webpack are not among them. But the reduction only runs when experimental.runtimeServerDeploymentId is enabled, because the full filter is a breaking change (from the comment in the source). Without the flag, the whole config is serialized, including turbopack.rules.
turbopack.rules is only read while compiling. Every Turbopack loader integration configures itself there, so whatever it passes as loader options ends up on the production server:
Size. In our case (a zero-runtime CSS-in-JS plugin, devup-ui) the rules first carried a prewarmed style sheet as loader options. config.turbopack grew with the app: about 4 KB on a small app and about 43 KB on a larger one, written three times (.json, .js, standalone server.js). We have since reduced it to a constant ~500 B, but any plugin can hit this.
Absolute paths. Loader options often hold absolute paths from the build machine (e.g. C:\Users\<name>\project\theme.json). These end up in deployed artifacts.
No supported way to opt out.
compiler.runAfterProductionCompile runs before the manifest is written, but it does not receive the config, and the config has already been cloned by loadConfig.
An adapter's modifyConfig also changes the config the build uses, so removing the rules there removes them from Turbopack too.
An adapter's onBuildComplete runs after the files are written, but a project can only have one adapter (deployment platforms use their own), and the standalone server.js is generated afterwards from the in-memory object.
webpack already avoids this by accident: it is a function, so JSON.stringify drops it. turbopack.rules is plain data, so it is kept.
Proposal
Always omit the build-only keys turbopack and webpack (and possibly other compile-time-only keys such as sassOptions or compiler) from the config written for runtime, independent of runtimeServerDeploymentId. This could be a small allowlist/denylist step applied before the full getNextConfigRuntime filter.
If removing them by default is too risky, a supported opt-in would also help. That could be a documented flag, or a hook that receives the runtime config object before it is written.
After next build, .next/required-server-files.json contains config.turbopack.rules with the 10 KB option and the absolute __dirname. So do required-server-files.js and, with output: 'standalone', server.js.
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
Goals
turbopack,webpack) out of the deployed output (.next/required-server-files.json,.next/required-server-files.js, and the standaloneserver.js).turbopack.ruleswithout those options being shipped to production servers.experimental.runtimeServerDeploymentId.Non-Goals
images,i18n,basePath,experimental.serverActions, …) are written.Background
next buildwrites the resolvednext.configinto.next/required-server-files.jsonand its.jstwin.writeStandaloneDirectorythen embeds the same object into the standaloneserver.jsasconst nextConfig = …. This is hownext startand standalone servers get their config without evaluatingnext.configagain.The object comes from
getNextConfigRuntime(config)inpackages/next/src/server/config-shared.ts. That function already reduces the config to the keys the server needs at runtime, andturbopackandwebpackare not among them. But the reduction only runs whenexperimental.runtimeServerDeploymentIdis enabled, because the full filter is a breaking change (from the comment in the source). Without the flag, the whole config is serialized, includingturbopack.rules.turbopack.rulesis only read while compiling. Every Turbopack loader integration configures itself there, so whatever it passes as loader options ends up on the production server:config.turbopackgrew with the app: about 4 KB on a small app and about 43 KB on a larger one, written three times (.json,.js, standaloneserver.js). We have since reduced it to a constant ~500 B, but any plugin can hit this.C:\Users\<name>\project\theme.json). These end up in deployed artifacts.compiler.runAfterProductionCompileruns before the manifest is written, but it does not receive the config, and the config has already been cloned byloadConfig.modifyConfigalso changes the config the build uses, so removing the rules there removes them from Turbopack too.onBuildCompleteruns after the files are written, but a project can only have one adapter (deployment platforms use their own), and the standaloneserver.jsis generated afterwards from the in-memory object.experimental.runtimeServerDeploymentIddoes remove them, but it also changes howNEXT_DEPLOYMENT_IDis inlined. It has open issues (Auto-enabledexperimental.runtimeServerDeploymentIdbreaks Skew Protection for prebuilt Vercel deployments (custom deploymentId is overridden by runtime dpl_ ID) #94734, runtimeServerDeploymentId: prerendered flight payloads pin the build-time deployment id — serving a build under a different deployment id causes an infinite MPA reload loop #98078), so a plugin can't turn it on for its users.webpackalready avoids this by accident: it is a function, soJSON.stringifydrops it.turbopack.rulesis plain data, so it is kept.Proposal
Always omit the build-only keys
turbopackandwebpack(and possibly other compile-time-only keys such assassOptionsorcompiler) from the config written for runtime, independent ofruntimeServerDeploymentId. This could be a small allowlist/denylist step applied before the fullgetNextConfigRuntimefilter.If removing them by default is too risky, a supported opt-in would also help. That could be a documented flag, or a hook that receives the runtime config object before it is written.
Repro on Next 16.4.6, App Router, Turbopack:
After
next build,.next/required-server-files.jsoncontainsconfig.turbopack.ruleswith the 10 KB option and the absolute__dirname. So dorequired-server-files.jsand, withoutput: 'standalone',server.js.All reactions