Repository navigation
fix(build): refuse a Turbopack config in withAstryx instead of building unstyled - #6109
Conversation
…ng unstyled withAstryx() installs every alias it needs inside nextConfig.webpack, and Turbopack never calls that hook. So withAstryx() under Turbopack reinstates exactly the failure meta#5932 removed: the app resolves @astryxdesign/* through `default` to dist, whose runtime class names are disjoint from the CSS the PostCSS pass compiles out of source, and the build succeeds with an unstyled page and nothing logged. There is no configuration in which that combination does what the author intended, so this refuses rather than warning -- an unstyled production deploy costs more than a failed build. The message names both ways out: keep the source build and pass --webpack, or drop withAstryx() and consume the pre-built package. Detected with process.env.TURBOPACK, which Next sets for both `next dev --turbopack` and `next build --turbopack`, in the parent process and in each build worker. Also reports an empty alias map. sourceEntryAliases() skips a package that is not installed or whose export map ships no `source` condition, which is correct per package -- an app need not depend on all three. Skipping every one of them is not: the result is zero aliases, which is the pre-0.5.3 config, and the app goes back to resolving dist against source-compiled CSS. That reads as working right up to the unstyled page. A warning rather than a throw, because an install layout this helper cannot walk is not proof the build is wrong. Six tests added, 27 passing in packages/build/src/next.test.mjs. Verified against a real Next 16.3.4 app on 0.5.3: `next build --turbopack` now fails at config load with the message, where before it exited 0 and served a page with 134 of 141 rendered classes having no matching CSS rule; `next build --webpack` still builds and prerenders static. Fixes meta#5921
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
Hi @joaodotwork! Thank you for your pull request and welcome to our community. Action RequiredIn order to merge any pull request (code, docs, etc.), we require contributors to sign our Contributor License Agreement, and we don't seem to have one on file for you. ProcessIn order for us to review and merge your suggested changes, please sign at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need to sign the corporate CLA. Once the CLA is signed, our tooling will perform checks and validations. Afterwards, the pull request will be tagged with If you have received this in error or have any questions, please contact us at [email protected]. Thanks! |
|
CLA signed. The Meta CLA check on this PR ran at 10:34 UTC, before the signature, so it is showing a stale Everything else is green: |
|
Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Meta Open Source project. Thanks! |
|
Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Meta Open Source project. Thanks! |
Categorised [breaking] rather than [fix] because the throw turns a currently-succeeding build into a failing one, and that is the breaking tier under check-changesets' coupling while 0.x. Worth a maintainer's eye rather than mine: all publishable packages are a fixed group, so this co-bumps the whole system to a new minor. If that cost is not worth the guard, warn instead and the changeset becomes [fix] + patch.
|
Marked ready for review, and added the changeset. I had left this as a draft pending the throw-versus-warn answer on #5921, which was the wrong way round: The changeset is So the two coherent shapes are:
Happy to switch to the warn shape on a word; it is a one-line change plus a changeset edit. I have implemented the throw because an unstyled production deploy costs more than a failed build, and because there is no configuration in which One note on CI: |
cixzhang
left a comment
There was a problem hiding this comment.
Thanks for digging into the silent styling failure. Two things need changing before this is safe to ship.
packages/build/src/next.js:270: empty generated aliases are not the same as an ineffective config. I reproduced a caller alias that resolves correctly while this warning still says the app “will render unstyled.” A working caller alias must stay quiet; warn only when effective source resolution is actually missing..changeset/refuse-turbopack-in-with-astryx.md:2: this is not a breaking release. A valid supported Turbopack source build did not work before; explicit Turbopack built broken output, while Next 16.3.4 already rejects the default-Turbopack/webpack-config combination. This should be a patch rather than[breaking]/minor.
If you'd rather talk it through with someone, we're in Discord.
[Reviewed by Robohands]
… map Addresses review on meta#6109. The warning tested the wrong thing. It fired when sourceEntryAliases() produced nothing, but generating nothing is not a fault on its own: a caller alias that already routes the packages is a working config this helper has nothing to add to, and it was told it would "render unstyled". The check now runs against the MERGED alias map and asks whether anything claims an astryx request at all -- generated or caller-supplied, object or array shaped, from the config or from the caller's own webpack hook. Where a caller points its alias is its business; the only fault is an alias map that names none of the packages, which is the pre-0.5.3 config. Three regression tests for the case raised in review: a caller alias in the config, the array-shaped form, and one contributed from the caller's webpack hook. All three must stay quiet. 30 passing. Changeset drops from [breaking]/minor to [fix]/patch. The reviewer is right and I had this wrong: no working configuration is lost. Verified on Next 16.3.4 -- `next build` with a webpack config and no turbopack config already fails on its own ("This build is using Turbopack, with a `webpack` config and no `turbopack` config"), and explicit --turbopack was already producing an unstyled build. So the only behaviour this changes was broken before. Re-verified end to end: --webpack builds, prerenders static, and does not warn; --turbopack refuses at config load.
|
Both addressed in The warning tested the wrong thing. It fired when Three regression tests for exactly the case you reproduced — a caller alias in the config, the array-shaped form, and one contributed from the caller's The changeset is now So the three cases before this PR were: default → Next already errors; explicit Re-verified end to end on 0.5.3 + this branch:
|
cixzhang
left a comment
There was a problem hiding this comment.
Thanks for fixing the caller-prefix case and the release classification. Two things still need changing before this is ready.
packages/build/src/next.js:200: wildcard aliases still take the false-warning path. The existing resolver tests prove@astryxdesign/*resolves successfully, but the same test run now logs “none was configured” becausealiasCoversAstryx()compares the literal*key against concrete package names. Please make working wildcard aliases from the config or caller hook stay quiet and add warning assertions around those existing resolver cases.packages/build/README.md:99: the public source-build setup still depends onnextConfig.webpackbut never says Next 16 must run with--webpack. Someone can still explicitly select Turbopack and get the unstyled build this PR is meant to prevent. Please document the requirement here and in the source example before this closes #5921.
If you'd rather talk it through with someone, we're in Discord.
[Reviewed by Robohands]
PR Analysis Report📚 Storybook PreviewView Storybook for this PR 🧪 Sandbox PreviewView Sandbox for this PR No new or modified components detected. Bundle Size SummaryNo component packages changed. Accessibility AuditStatus: No accessibility violations detected. Generated by PR Enrichment workflow | Storybook | Sandbox | View full report |
|
Acknowledged — both points land, and I reproduced the first before touching it. 1. Wildcard false warning — confirmed and fixed locally. With a caller wildcard, The fix reuses the Also added the warning assertions you asked for, as a 2. Documentation — not done yet. Fair, and it is the part that actually closes #5921: the guard stops the helper being used wrongly, but the README still describes a setup whose bundler requirement is invisible. I will add the Pushing both together rather than piecemeal, so you get one re-review rather than two. Nothing else outstanding from either review as far as I can tell — no inline threads on my side, and the enrichment report is clean (no components changed, no bundle delta, no a11y violations). |
Addresses the second review on meta#6109. Wildcard aliases took the false-warning path. With a caller wildcard, withoutCallerOverrides() correctly drops every generated entry the pattern claims, so the merged map comes out as exactly ["@astryxdesign/*"] -- and aliasCoversAstryx() compared that literal key against concrete package names, found no coverage and warned about a config that resolves fine. Reproduced standalone: one warning before, none after. The fix reuses wildcardPattern(), already in the file and already used by withoutCallerOverrides() to decide what a caller has spoken for, so the two functions now agree on what a wildcard claims instead of disagreeing. Warning assertions added as a beforeEach/afterEach pair around the whole existing withAstryx resolver block rather than per case: every config in there resolves successfully, so none may warn. A future coverage check that misreads a working alias now fails the suite instead of logging into it, which is what mine did. 30 passing. Documents the bundler requirement, which is the part that actually closes meta#5921 -- the guard stops the helper being used wrongly, but the README described a setup whose bundler requirement was invisible: - packages/build/README.md: a note at the top of Next.js Setup explaining that the whole section works through nextConfig.webpack, that Turbopack never calls it, that Next 16 defaults to Turbopack so the bundler has to be named, and that the pre-built package is the way out if pinning it is unwelcome. Plus a pointer at the next.config step. - apps/example-nextjs-source/README.md: the same requirement, scoped to what that example actually runs. Deliberately did NOT add --webpack to the example's scripts. The example pins next ^15.5.21, and --webpack is a Next 16 flag -- [email protected] ships zero occurrences of it while it does ship --turbopack. Passing it there would break the example, so the README says the plain scripts are correct under the Next 15 pin and names the flag as what Next 16 needs.
|
Both addressed in Wildcard coverage. The fix reuses Warning assertions are a Documentation. A note at the top of One thing I deliberately did not do: add Happy to bump that example to Next 16 and make the scripts explicit if you would rather have it demonstrating the Next 16 path, but that felt like a maintainer's call on the example rather than something to fold into this fix.
|
cixzhang
left a comment
There was a problem hiding this comment.
Thanks, the wildcard cases, release classification, and Next 15/16 guidance are fixed. One working alias shape still hits the original false-warning problem.
packages/build/src/next.js:209: a scope-prefix alias such as {'@astryxdesign': customRoot} correctly resolves @astryxdesign/core through the caller path, but aliasCoversAstryx() checks the prefix in the opposite direction and logs that no alias was configured. I reproduced this for object, array, and caller-hook aliases. Please keep these working prefix aliases quiet too and cover them with the same warning assertions.
If you'd rather talk it through with someone, we're in Discord.
[Reviewed by Robohands]
Addresses the third review on meta#6109. A scope-level key such as {'@astryxdesign': customRoot} matches no package name as a string, but webpack resolves @astryxdesign/core through it because the key is an ancestor of the request. aliasCoversAstryx() only looked the other way down the tree, so it reported that nothing was configured. Reproduced for the object, array and caller-hook forms. The root cause is that this predicate had been enumerating alias shapes -- empty generated map, then wildcards, now scope prefixes -- each fix correct for the case named and blind to the next. It now applies webpack's own rule instead: a non-exact alias `key` intercepts a request R when R === key or R starts with `${key}/`, so an entry covers the packages when one of them sits at or below its key. A key under a package still counts, since that is the shape of the entries this helper generates, and a `*` key claims by pattern. Verified across every shape: scope prefix (object, array, hook), wildcard, package prefix, exact `$` key, and subpath key all stay quiet, while a config that routes nothing still warns. Three tests added for the scope-prefix forms; 33 passing. Also records why this errs toward silence: a false positive tells someone their working build is broken, a false negative merely says nothing.
|
Good catch, and reproduced for all three forms before fixing — You've now found three cases in this one check, and the reason is that I kept enumerating alias shapes rather than applying webpack's rule. So it now uses the rule: a non-exact alias Checked every shape I could think of — scope prefix (object, array, hook), wildcard, package prefix, exact I also noted in the code why this errs toward silence: a false positive tells someone their working build is broken, whereas a false negative just says nothing. If you'd still rather this check didn't exist — the Turbopack throw is what actually closes #5921 and it hasn't been in question — I'm happy to drop it. Your call, and no attachment on my side. |
cixzhang
left a comment
There was a problem hiding this comment.
Thanks, the working scope-prefix cases now resolve quietly across object, array, and caller-hook aliases. One exact-alias case still suppresses the new missing-resolution warning.
packages/build/src/next.js:227: aliasCoversAstryx() strips $ and ignores array onlyModule, then applies prefix matching. So @astryxdesign$ (or {name: '@astryxdesign', onlyModule: true}) resolves no Astryx package but suppresses the new warning. I reproduced this in object, array, and hook forms: all three fail to resolve @astryxdesign/core and log zero warnings. Please preserve exactness when checking coverage and assert these ineffective exact-scope aliases warn.
If you'd rather talk it through with someone, we're in Discord.
[Reviewed by Robohands]
Addresses the fourth review on meta#6109. aliasCoversAstryx() stripped a trailing `$` from object keys and never looked at onlyModule on array entries, then prefix-matched. So '@astryxdesign$' and {name: '@astryxdesign', onlyModule: true} read as ancestors of the packages and bought silence, while matching only the bare scope specifier -- which nothing imports -- and routing no package at all. Reproduced in the object, array and caller-hook forms. Exactness now threads through from both sources, and it removes the ancestor case and only that one: an exact key at or below a package still routes a real request, so '@astryxdesign/core$', its array equivalent and an exact subpath key stay quiet, while '@astryxdesign$' warns. This is the first of these cases where the check was too quiet rather than too loud. The bias toward silence is right for an ambiguous config, but an exact-scope key is not ambiguous -- it is determinately ineffective -- so the comment now says which of the two it is. Also corrects the message, which claimed "none was configured". In this case one is configured and simply does not match, so it now reports that no alias routes the packages and names the exact-key trap. Six tests: three asserting the ineffective exact-scope forms warn, three holding the boundary where an exact key does route a request. They use an app with nothing installed, since a present package is routed by the generated entries and there is correctly nothing to report. 39 passing.
|
Right on both counts —
Six tests — three asserting each ineffective form warns, three holding that boundary. They use an app with nothing installed; with a package present the generated entries route it and there is correctly nothing to report, which is what hid this from me. 39 passing. One thing your note made me notice: the message still said "and none was configured", which is untrue here — something is configured, it just doesn't match. It now says no alias routes the packages and names the exact-key trap by way of explanation. This is also the first of these where the check was too quiet rather than too loud, and it's a useful correction to a line I'd written into the comment. Erring toward silence is right for an ambiguous config, but an exact-scope key isn't ambiguous — it's determinately ineffective — so the comment now distinguishes the two rather than blanket-preferring silence. One case I've deliberately left quiet, flagging it in case you'd rather it didn't: And thanks for the Discord offer across these — I've been fine on the thread, but if a fifth round would be quicker spoken than written I'll happily take you up on it. |
cixzhang
left a comment
There was a problem hiding this comment.
Thanks, this now handles exact scope aliases across object, array, and hook forms. Working aliases stay quiet, and the documented Next 15/16 source-build paths pass.
[Reviewed by Robohands]
Fixes #5921. Draft while the one compatibility question on that issue is open — see the end.
Problem
withAstryx()installs every alias it needs insidenextConfig.webpack, and Turbopack never calls that hook. SowithAstryx()under Turbopack reinstates exactly the failure #5932 removed: the app resolves@astryxdesign/*throughdefaulttodist, whose runtime class names are disjoint from the CSS the PostCSS pass compiles out of source, and the build succeeds with an unstyled page and nothing logged.Next 16 defaults to Turbopack, so a project scaffolded today gets the unstyled page from a correctly configured source build. That is why this is separate from #5920 rather than a regression of it.
Change
1. Refuse under Turbopack (
assertWebpack(), called at config construction). There is no configuration in which the combination does what the author intended, so it throws rather than warning — an unstyled production deploy costs more than a failed build. The message names both ways out: keep the source build and pass--webpack, or dropwithAstryx()and consume the pre-built package.Detection is
process.env.TURBOPACK, verified rather than assumed — Next 16.3.4 setsTURBOPACK=1for bothnext dev --turbopackandnext build --turbopack, in the parent process and in each build worker, and leaves it unset under--webpack.2. Report an empty alias map.
sourceEntryAliases()skips a package that is not installed, or whose export map ships nosourcecondition. Correct per package — an app need not depend on all three. Skipping every one of them is not: the result is zero aliases, which is the pre-0.5.3 config, and the app goes back to resolving dist against source-compiled CSS. Aconsole.warnrather than a throw, because an install layout this helper cannot walk is not proof the build is wrong.Evidence
Unit tests: 6 added, 27 passing in
packages/build/src/next.test.mjs, no changes to the existing 21.End to end against a real Next 16.3.4 app on
0.5.3, measured on the served HTML and CSS rather than the exit code:next build --turbopack/prerenders, 134 of 141 rendered classes have no matching CSS rulenext build --webpack○ (Static)The harness that produces the unmatched-class count builds each documented setup under both bundlers, serves it, and cross-checks every class on a rendered element against the served stylesheet. Happy to extract it as a standalone repro if useful — it is what turned up #5920.
The open question
From #5921, and the reason this is a draft: throw or warn for the Turbopack case?
A throw is the useful behaviour, but it turns a currently-succeeding build into a failing one — a break for anyone who has
withAstryx()in a Turbopack config and has not noticed, which is exactly the population this issue is about. This PR implements the throw; switching it to a warn is a one-line change if you would rather not take that in a0.xminor.I have left the changeset off until that is settled, since the category (
fixvsbreaking) follows from the answer and drives the bump.Checked
mainand the open PRs first perAGENTS.md:packages/build/src/next.jsis unchanged sincebea53b23and no open PR touches it.