cloudflare / cloudflare/vinext
`react-server` export condition missing in CF Workers bundle causes deploy failure
- Dominant language
- TypeScript
- Stars
- 8.8k
- Forks
- 406
- Avg merge
- 2d 6h
- Merged PRs (30d)
- 120
Description
## Problem
When deploying a vinext app to Cloudflare Workers, wrangler rejects the upload with:
```
Uncaught Error: The "react" package in this environment is not configured correctly.
The "react-server" condition must be enabled in any environment that runs React Server Components.
```
## Root cause
vinext's `configResolved` hook creates its own `environments.rsc` config that **overrides** the one from `@vitejs/plugin-rsc`, which sets `resolve.conditions: ["react-server", ...defaultServerConditions]` ([plugin-rsc source, line 242](https://github.com/nicolo-ribaudo/vite-plugin-rsc/blob/main/packages/vite-plugin-rsc/src/plugin.ts)).
Without the `react-server` condition, the RSC environment bundles the standard `react` export (which only exposes `__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE`). The `react-server-dom-webpack` server code checks for `React.__SERVER_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE` at module init — it's undefined, so it throws.
Additionally, when `@cloudflare/vite-plugin` re-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
```ts
// vite.config.ts
import vinext from "vinext";
import { cloudflare } from "@cloudflare/vite-plugin";
import { defineConfig } from "vite";
export default defineConfig({
plugins: [vinext(), cloudflare()],
});
```
```bash
vite build # succeeds
vinext deploy # fails with react-server error
```
## Workaround
Users can re-add the condition in their `vite.config.ts`:
```ts
import { defineConfig, defaultServerConditions } from "vite";
export default defineConfig({
// ...
environments: {
rsc: {
resolve: {
conditions: ["react-server", ...defaultServerConditions],
},
},
},
});
```
Plus a post-build patch to fix the worker entry (since the cloudflare plugin's worker environment still bundles without the condition):
```ts
// In the built worker entry, replace:
// ReactSharedInternalsServer = React2.__SERVER_INTERNALS_...;
// with:
// ReactSharedInternalsServer = (React2.__SERVER_INTERNALS_... = React2.__SERVER_INTERNALS_... || React2.__CLIENT_INTERNALS_...);
```
## Suggested fix
In `vinext/dist/index.js` around line 1868, the `environments.rsc` config should include:
```ts
resolve: {
conditions: ["react-server", ...defaultServerConditions],
// existing external config...
}
```
The SSR bundle also needs consideration since it's re-bundled into the CF worker entry.
## Environment
- vinext: 0.0.7
- vite: 7.3.1
- @cloudflare/vite-plugin: 1.29.0
- @vitejs/plugin-rsc: 0.5.21
- react: 19.2.4
- wrangler: 4.74.0
Contributor guide
Assessment
This issue has not been assessed yet.