Repository navigation
[16.x] Turbopack: don't strip async-module runtime from shared runtime chunks - #96653
Merged
Merged
Conversation
#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 #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. (cherry picked from commit a75ece1)
Contributor
Stats from current PR🔴 2 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: 1d24e2d |
Contributor
Tests PassedCommit: 1d24e2d |
lukesandberg
marked this pull request as ready for review
August 4, 2026 18:05
lukesandberg
enabled auto-merge (squash)
August 4, 2026 18:05
sampoder
approved these changes
Aug 4, 2026
jhodapp
added a commit
to refactor-group/refactor-platform-fe
that referenced
this pull request
Aug 18, 2026
16.3.1 leads with "Turbopack: don't strip async-module runtime from shared runtime chunks" (vercel/next.js#96653). `__turbopack_context__.a` is that async-module helper, so this is the upstream fix for the intermittent cold `next build` failure this branch works around. Verified: with 16.3.1 and the ORIGINAL CommonJS postcss config restored, 0 failures across 12 cold builds, where 16.3.0 failed 3 of 13. The ESM config change is therefore no longer load-bearing and is kept for repo consistency rather than as the fix. eslint-config-next bumped in lockstep. Suite unchanged: 163 files / 1745 tests, chromium Playwright 45 passed / 22 skipped.
jhodapp
added a commit
to refactor-group/refactor-platform-fe
that referenced
this pull request
Aug 18, 2026
16.3.1 leads with "Turbopack: don't strip async-module runtime from shared runtime chunks" (vercel/next.js#96653). `__turbopack_context__.a` is that async-module helper, so this is the upstream fix for the intermittent cold `next build` failure this branch works around. Verified: with 16.3.1 and the ORIGINAL CommonJS postcss config restored, 0 failures across 12 cold builds, where 16.3.0 failed 3 of 13. The ESM config change is therefore no longer load-bearing and is kept for repo consistency rather than as the fix. eslint-config-next bumped in lockstep. Suite unchanged: 163 files / 1745 tests, chromium Playwright 45 passed / 22 skipped.
Ducksss
added a commit
to Ducksss/payload-components
that referenced
this pull request
Aug 28, 2026
…me flake (#509) 16.3.0 has a race in Turbopack production builds: the fixed-path shared runtime chunk is emitted once per module graph, and a graph with no async modules writes a variant with the async-module helper stripped, clobbering the complete one — so build-time postcss/font evaluations intermittently fail with 'TypeError: __turbopack_context__.a is not a function' (emission order decides the winner). This redded our CI release-gate 2-in-3 runs on 2026-08-27/28 while identical commits built green locally. Fixed upstream in 16.3.1 (vercel/next.js#96653, backport of #96599); 16.3.3 is the current patch. eslint-config-next moves in lockstep. Co-authored-by: Claude Fable 5 <[email protected]>
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.
Backports #96599 ("Turbopack: don't strip async-module runtime from shared runtime chunks") to
next-16-3.