Repository navigation
Turbopack: don't strip async-module runtime from shared runtime chunks - #96599
Merged
Merged
Conversation
lukesandberg
marked this pull request as ready for review
August 4, 2026 07:29
sampoder
approved these changes
Aug 4, 2026
sampoder
left a comment
Contributor
There was a problem hiding this comment.
change to add shared_runtime_chunk makes sense to me though its unfortunate :/
I'm 50/50 on adding per_page_module_graph it seems like it might be a little overkill.
lukesandberg
marked this pull request as draft
August 4, 2026 07:38
The runtime chunk is emitted to a fixed path, so every module graph using a chunking context writes the same `[turbopack]_runtime.js`. Since #94376 the async-module (top-level await) machinery is omitted when a graph has no async modules, but that decision was made per-graph. Contexts shared by several independent graphs therefore produce two different runtimes for one path. The Next.js node execution context is shared by every build-time JS evaluation (postcss configs, webpack loaders, next/font/google), each with its own graph. A graph without async modules would emit a runtime without `.a` and clobber the variant a postcss config's top-level `await` needs, failing at build time with `__turbopack_context__.a is not a function`. Which variant landed depended on emission order, so it reproduced intermittently. Add `shared_runtime_chunk` to NodeJsChunkingContext and set it on the shared node execution contexts, so those always emit the complete runtime. This matches the existing dev carve-out: in both cases a single graph can't see everything sharing the runtime. On the browser side the equivalent check tested `RuntimeType::Development` as a proxy for per-page graphs. That happens to work only because `per_page_module_graph` is currently `mode == Development`; plumb the real flag through instead. Also rename `has_async_modules` to `include_async_module_runtime`, since the value is now true whenever we can't tell rather than meaning the graph has async modules.
Both contexts now call it `shared_runtime_chunk`. The browser side was named after the setting that feeds it rather than the constraint it expresses.
lukesandberg
force-pushed
the
post_css_async_loader
branch
from
August 4, 2026 07:45
afd5b7e to
f1ac0f0
Compare
Contributor
Tests PassedCommit: 534c9c9 |
Contributor
Stats from current PR🔴 3 regressions
📊 All Metrics📖 Metrics GlossaryDev Server Metrics:
Build Metrics:
Change Thresholds:
⚡ Dev Server
📦 Dev Server (Webpack) (Legacy)📦 Dev Server (Webpack)
⚡ Production Builds
📦 Production Builds (Webpack) (Legacy)📦 Production Builds (Webpack)
📦 Bundle SizesBundle Sizes⚡ TurbopackClient Main Bundles
Server Middleware
Build DetailsBuild Manifests
Build Cache
📦 WebpackClient Main Bundles
Polyfills
Pages
Server Edge SSR
Middleware
Build DetailsBuild Manifests
Build Cache
🔄 Shared (bundler-independent)Runtimes
📎 Tarball URLCommit: 534c9c9 |
Contributor
Author
|
yeah still tweaking the names. `per-page-module-graph' doesn't work in the specific case of loaders (no pages!) so 'shared_runtime_chunk' inferred from per-page-module-graph seems better |
lukesandberg
marked this pull request as ready for review
August 4, 2026 08:19
lukesandberg
enabled auto-merge (squash)
August 4, 2026 08:19
The Node.js gate also matched on RuntimeType::Production, which stood in for "the graph covers the whole app". Callers now set shared_runtime_chunk from per_page_module_graph instead, so the check is redundant and the node gate matches the browser one. Plumb per_page_module_graph through ServerChunkingContextOptions, and set shared_runtime_chunk on the turbopack-cli dev ExecutionContext, which is shared by every build-time evaluation and was previously only covered by the RuntimeType::Development branch. Dev graphs that are self-contained now get the optimization too, which the RuntimeType check previously blocked: the debug-ids/node snapshot drops 132 lines of async-module machinery its graph never uses.
lukesandberg
marked this pull request as draft
August 4, 2026 08:20
auto-merge was automatically disabled
August 4, 2026 08:20
Pull request was converted to draft
lukesandberg
marked this pull request as ready for review
August 4, 2026 08:20
lukesandberg
enabled auto-merge (squash)
August 4, 2026 08:21
lukesandberg
added a commit
that referenced
this pull request
Aug 4, 2026
m-kawafuji
pushed a commit
to m-kawafuji/next.js
that referenced
this pull request
Aug 8, 2026
vercel#96599) ### What? Turbopack could emit a `[turbopack]_runtime.js` without the async-module (top-level await) machinery while chunks written next to it call `__turbopack_context__.a(...)`, failing production builds with `TypeError: __turbopack_context__.a is not a function`. Reported against 16.3 when loading a `postcss.config.js`. Intermittent, production only. ### Why? The runtime chunk is emitted to a fixed path, so every module graph using a chunking context writes the same file. Since vercel#94376 the async-module machinery is dropped when a graph has no async modules — but that's decided per graph. The Next.js node execution context is shared by every build-time JS evaluation (postcss configs, webpack loaders, `next/font/google`), each with its own `ModuleGraph`. A graph with no async modules emits a runtime without `.a` and clobbers the variant the postcss loader needs. The winner is `assets.first()` in `emit_assets`, which depends on emission order — hence the intermittency. ### How? Add `shared_runtime_chunk` to the chunking contexts and set it where one runtime is shared by several graphs, so those always emit the complete runtime. This matches the carve-out that already exists for development: in both cases a single graph can't see everything sharing the runtime. Whole-app server contexts keep the optimization. The browser side tested `RuntimeType::Development` as a proxy for per-page graphs, which only works because `per_page_module_graph` currently *is* `mode == Development`. It now reads the real flag. Also renames `has_async_modules` to `include_async_module_runtime`, since it's now true whenever we can't tell. I audited the rest of `.next/build/` for the same hazard: the runtime chunk (and its `.map`) was the only fixed-path output. Everything else is content-hashed via `AssetIdent::output_name`. ### Testing `test/production/app-dir/turbopack-shared-runtime-async-module` uses a single synchronous loader — enough on its own to produce the stripped runtime. Verified to fail without the fix and pass with it. `cargo test -p turbopack-tests` passes with no snapshot churn. Follow-up, not in this PR: the conflict is silent. `EmitConflictIssue` is `IssueSeverity::Error` but never fired here, because the two runtimes weren't grouped into one `emit_assets` call.
This was referenced Aug 10, 2026
N2D4
added a commit
to hexclave/hexclave
that referenced
this pull request
Aug 14, 2026
…1959) Dashboard production builds fail intermittently with: ``` ./apps/dashboard/src/app/globals.css Error: Error evaluating Node.js code TypeError: __turbopack_context__.a is not a function at mod (apps/dashboard/postcss.config.js_.loader.mjs:11:31) ``` ## Root cause An upstream Turbopack bug, not our cache configuration. Turbopack emits the shared runtime chunk to one fixed path (`.next/build/chunks/[turbopack]_runtime.js`), but strips the async-module machinery per module graph. Next's build-time Node.js evaluation context is shared across graphs (postcss config, loaders, next-font), so a graph containing no async modules emits a runtime without `.a` and overwrites the one the postcss loader calls. Which version wins depends on emission order, hence the intermittency and the "production only" signature. Fixed upstream by vercel/next.js#96599, backported in #96653, released in `[email protected]`. ## Changes - `next` 16.3.0 → 16.3.1 in the four apps that pin it directly (dashboard, mcp, internal-tool, skills). - `minimumReleaseAgeExclude` entries moved from 16.3.0 to 16.3.1 (`minimumReleaseAge` itself unchanged). 16.3.1 is younger than the 7-day window; taking it early was explicitly approved because it carries this fix. - `turbo.json`: build outputs are now `.next/**` + `!.next/cache/**` + `!.next/dev/**`, matching turborepo's own `examples/basic`. Independent of the bug — Turbopack's persistent cache under `.next/cache` was being packed into turbo artifacts (610 MB → 54 MB for the dashboard build), and neither cache state nor dev-server state (`.next/dev`, which `next build` never writes) belongs in a build artifact. ## Validation Upstream regression fixture (`test/production/app-dir/turbopack-shared-runtime-async-module` from the fix commit), checking the emitted runtime chunk for the `asyncModule` machinery: | next | `asyncModule` in emitted runtime | | --- | --- | | 16.3.0 | absent | | 16.3.1 | present | That is the mechanism, fail → pass. Dashboard: 20 consecutive production builds with a warm `.next` on each version — 0 failures on both, all 40 runs emitted a runtime containing `asyncModule`. The failure is emission-order dependent and did not surface locally in either arm, so this is a "no regression" signal, not a local reproduction of the failure. `typecheck`, `lint`, `build`, `build:rde-standalone` pass, as do builds of the three other upgraded apps. Link to Devin session: https://app.devin.ai/sessions/f9469ed89c4d4d668f53c6622e404984 Requested by: @N2D4 --------- Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What?
Turbopack could emit a
[turbopack]_runtime.jswithout the async-module (top-level await) machinery while chunks written next to it call__turbopack_context__.a(...), failing production builds withTypeError: __turbopack_context__.a is not a function.Reported against 16.3 when loading a
postcss.config.js. Intermittent, production only.Why?
The runtime chunk is emitted to a fixed path, so every module graph using a chunking context writes the same file. Since #94376 the async-module machinery is dropped when a graph has no async modules — but that's decided per graph.
The Next.js node execution context is shared by every build-time JS evaluation (postcss configs, webpack loaders,
next/font/google), each with its ownModuleGraph. A graph with no async modules emits a runtime without.aand clobbers the variant the postcss loader needs. The winner isassets.first()inemit_assets, which depends on emission order — hence the intermittency.How?
Add
shared_runtime_chunkto the chunking contexts and set it where one runtime is shared by several graphs, so those always emit the complete runtime. This matches the carve-out that already exists for development: in both cases a single graph can't see everything sharing the runtime. Whole-app server contexts keep the optimization.The browser side tested
RuntimeType::Developmentas a proxy for per-page graphs, which only works becauseper_page_module_graphcurrently ismode == Development. It now reads the real flag.Also renames
has_async_modulestoinclude_async_module_runtime, since it's now true whenever we can't tell.I audited the rest of
.next/build/for the same hazard: the runtime chunk (and its.map) was the only fixed-path output. Everything else is content-hashed viaAssetIdent::output_name.Testing
test/production/app-dir/turbopack-shared-runtime-async-moduleuses a single synchronous loader — enough on its own to produce the stripped runtime. Verified to fail without the fix and pass with it.cargo test -p turbopack-testspasses with no snapshot churn.Follow-up, not in this PR: the conflict is silent.
EmitConflictIssueisIssueSeverity::Errorbut never fired here, because the two runtimes weren't grouped into oneemit_assetscall.