mirror of
https://github.com/cloudflare/vinext.git
synced 2026-05-09 08:25:34 +02:00
[GH-ISSUE #572] react-server export condition missing in CF Workers bundle causes deploy failure #123
Labels
No labels
enhancement
enhancement
good first issue
help wanted
nextjs-tracking
nextjs-tracking
pull-request
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
starred/vinext#123
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @lucharo on GitHub (Mar 17, 2026).
Original GitHub issue: https://github.com/cloudflare/vinext/issues/572
Problem
When deploying a vinext app to Cloudflare Workers, wrangler rejects the upload with:
Root cause
vinext's
configResolvedhook creates its ownenvironments.rscconfig that overrides the one from@vitejs/plugin-rsc, which setsresolve.conditions: ["react-server", ...defaultServerConditions](plugin-rsc source, line 242).Without the
react-servercondition, the RSC environment bundles the standardreactexport (which only exposes__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE). Thereact-server-dom-webpackserver code checks forReact.__SERVER_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADEat module init — it's undefined, so it throws.Additionally, when
@cloudflare/vite-pluginre-bundles the RSC + SSR outputs into the final worker entry, even if the RSC build used the correct condition, the worker environment deduplicates to one React copy (the standard one), losing the server internals assignment.Reproduction
Workaround
Users can re-add the condition in their
vite.config.ts:Plus a post-build patch to fix the worker entry (since the cloudflare plugin's worker environment still bundles without the condition):
Suggested fix
In
vinext/dist/index.jsaround line 1868, theenvironments.rscconfig should include:The SSR bundle also needs consideration since it's re-bundled into the CF worker entry.
Environment
@lucharo commented on GitHub (Mar 17, 2026):
Additional findings from minimal reproduction
We confirmed this is a vinext RSC runtime bug, not app-specific:
Minimal test — stripped layout to
<html><body>{children}</body></html>(no providers, no CSS, no metadata), page is just<div>Hello vinext</div>:__VINEXT_RSC_CHUNKS__script tag)TypeError: Cannot read properties of undefined (reading 'length')insidebuildFakeCallStack→resolveErrorDev→processFullBinaryRowRoot cause analysis (from deep-diving the bundle):
dist/server/index.js) correctly usesrequireReact_reactServer()with proper__SERVER_INTERNALSrequireReact()(client), creating two React instances with different internalsdist/server/ssr/index.js) also uses client React, but expects server error info formatstackfield → SSR'sbuildFakeCallStack(response, errorInfo.stack, ...)receivesundefined→ crashes onstack.lengthAdditional issues we patched around (documented in our PR #132):
__vite_rsc_assets_manifest.jsnot included in worker output (manual copy needed)../../server/ssr/to../server/ssr/)react-serverresolve condition dropped from@vitejs/plugin-rscby vinext'sconfigResolvedoverrideWe're moving away from Next.js entirely for our use case, but wanted to document the full findings for other users.
@camposcristian commented on GitHub (Apr 20, 2026):
Another data point from trying this workaround on a larger Next.js 16 App Router app:
Config applied (per the workaround above):
Result: the original
React.__SERVER_INTERNALSerror is resolved, but a secondary issue surfaces fromreact-dom/server.edge's pre-compiled CJS bundle. It contains literal top-level:These
require()calls survive vite's ESM conversion (they're inside a pre-compiled/minified vendor file). The bundle itself is fine-sized (~884 KiB raw for a moderate App Router app + next-international + shadcn), but deploy fails at Workers validation withUncaught ReferenceError: require is not defined.Tried workarounds that didn't stick:
rollup output.bannerinjecting arequireshim — the shim's ownimport from "react"stays external (banner is raw text, not processed by the resolver).createRequire(import.meta.url)—import.meta.urlisundefinedduring Workers upload validation, socreateRequirethrows.next/dist/compiled/ua-parser-jsto a stub for the earlier__dirnamevariant — works at build time but wrangler's upload-time rebundle re-resolved externals.The root seems to be that
react-dom/server.edge's inlinerequire()calls need to be rewritten at the source level during vinext's build, not via surrounding config. Filing this in case it helps triage alongside the react-server condition fix. Would be happy to share a minimal repro.Stack: vinext v0.0.7, vite 7.3.2, @cloudflare/vite-plugin (latest), @vitejs/plugin-rsc 0.5.24, Node 22.22.1, Next.js 16.1.6 App Router + next-international + server components.
@quant-risk commented on GitHub (May 4, 2026):
Relato de sucesso com upgrade 0.0.7 -> 0.0.47 + configuracao correta
O que passamos
Trevamos os mesmos erros descritos nesta issue:
react-server condition must be enabledno build do cloudflare vite-plugin__SERVER_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADEundefined no worker runtimeO que realmente resolveu
Upgrade para vinext 0.0.47 (estavamos na 0.0.7) e mudar a config do cloudflare plugin:
Errado (causa os erros desta issue):
Correto (RSC e SSR funcionam sem patching):
Isso faz o vinext gerar o wrangler.json em
dist/server/apontando para o RSC build correto, com client references comoregisterClientReferenceem vez de implementacoes reais no servidor. O deploy fica em ~8MB total (worker + assets estaticos em ASSETS binding).Produzido hoje
Deploy 100% funcional em:
duke-dashboard.henriq-costa91.workers.dev/,/pricing,/sign-in,/sign-upRecomendacao
Ajustar a documentacao do vinext para destacar que
viteEnvironmente obrigatorio para projetos Next.js App Router (com RSC). Quando o parametro nao e fornecido, o cloudflare rebundle perde as fronteiras client/server.