Registry / devops / vite-plugin-react-server

vite-plugin-react-server

JSON →
library2.0.1jsnpmunverified

Vite plugin for React Server Components (RSC) that transforms React components into native ESM modules, enabling static site generation, dynamic servers, and portable RSC payloads compatible with any HTTP server. Version 2.0.1 requires React 19.2+ and Node ^23.7.0, bundles the react-server-dom-esm transport via react-server-loader, and ships TypeScript types. Key differentiators: no experimental React builds needed, automatic client module detection via filename pattern or "use client" directive, built-in support for third-party client packages via peerDep detection, and a Storybook preset. Released under MIT, with active development on GitHub.

devops
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

Named export, not default. ESM only; no CJS support. TypeScript types included.

import { vitePluginReactServer } from 'vite-plugin-react-server'

Vite's config helper; always use ESM import. CJS require does not work in Vite config context.

import { defineConfig } from 'vite'

Must be top-of-file before any imports; leading whitespace, comments, and 'use strict' allowed above. Substring matches like 'clientUtils.tsx' are not treated as client modules.

// in Counter.tsx: "use client";

Minimal Vite config with a single server component page, plus dev and build commands.

// vite.config.ts import { defineConfig } from 'vite'; import { vitePluginReactServer } from 'vite-plugin-react-server'; export default defineConfig({ plugins: vitePluginReactServer({ moduleBase: 'src', Page: 'src/page.tsx', build: { pages: ['/'] }, }), }); // src/page.tsx export const Page = ({ url }: { url: string }) => <div>Hello from {url}</div>; // Run dev server: npx vite // Build static site: NODE_OPTIONS='--conditions react-server' vite build --app // Output: dist/static/ (HTML + RSC), dist/client/, dist/server/
Debug
Known footguns
breakingvite-plugin-react-server 2.0 requires React 19.2+ and Node ^23.7.0. Versions 1.x are incompatible.
breakingThe react-server-dom-esm transport is now bundled inside react-server-loader (auto-installed). You no longer install a transport package or an experimental React build.
deprecatedImporting from 'vite-plugin-react-server/experimental' is deprecated and will be removed in v3.
gotchaThird-party client packages like Chakra UI, MUI, Mantine cannot be imported directly into server components; they require a 'use client' wrapper.
gotchaFilename pattern for auto-detecting client modules: regex (^|[\/.])client\.[cm]?[jt]sx?$. Files like clientUtils.tsx or clients.tsx are NOT detected.
gotchaStorybook preset requires additional config in .storybook/main.ts; see docs for details.
Upgrade
Version history

Breaking-change detection hasn't run for this library yet.

Audit
Security & dependencies

CVE tracking and dependency tree are planned for a later release.

Agent activity
0 hits · last 30 days

No traffic data recorded yet.

Resources