Skip to content

react-server export condition missing in CF Workers bundle causes deploy failure #572

@lucharo

Description

@lucharo

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).

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

// vite.config.ts
import vinext from "vinext";
import { cloudflare } from "@cloudflare/vite-plugin";
import { defineConfig } from "vite";

export default defineConfig({
  plugins: [vinext(), cloudflare()],
});
vite build    # succeeds
vinext deploy # fails with react-server error

Workaround

Users can re-add the condition in their vite.config.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):

// 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:

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions