facebook/react · error · Error
The React Server Writer cannot be used outside a react-serve
Error message
The React Server Writer cannot be used outside a react-server environment. You must configure Node.js using the `--conditions react-server` flag.
What it means
The published static entry (npm/static.js) is the default (non-react-server) fallback for './static'. The real static APIs — the synchronous/static Flight writer used for edgeless or fully-buffered serialization — are only served under the 'react-server' export condition; without it this guard throws 'The React Server Writer cannot be used outside a react-server environment.'
Source
Thrown at packages/react-server-dom-webpack/npm/static.js:3
'use strict';
throw new Error(
'The React Server Writer cannot be used outside a react-server environment. ' +
'You must configure Node.js using the `--conditions react-server` flag.'
);
View on GitHub (pinned to eafeac097b)
Solutions
- Add 'react-server' to the runtime's resolve conditions (wrangler/esbuild build conditions, webpack conditionNames)
- In tests, set testEnvironmentOptions.customExportConditions = ['node', 'react-server'] or the runner's equivalent
- Run plain Node scripts with --conditions react-server
Example fix
// before (esbuild)
esbuild.build({entryPoints: ['worker.js'], conditions: ['worker']});
// after
esbuild.build({entryPoints: ['worker.js'], conditions: ['worker', 'react-server']}); Defensive patterns
Strategy: validation
Validate before calling
// esbuild/vite SSR: assert the condition is configured before build
const buildOpts = {conditions: ['node', 'import', 'react-server']};
if (!buildOpts.conditions.includes('react-server')) throw new Error('add react-server to conditions'); Prevention
- Keep the server bundle's conditionNames list in one shared config constant
- Test-build the server entry in CI to catch missing conditions
- Document the required conditions next to the runtime target
When it happens
Trigger: Importing react-server-dom-webpack/static (e.g. for the static writer used in edge-light/workerd runtimes or tests) without the react-server condition being set in the resolver.
Common situations: Workerd/Cloudflare Workers builds where the bundler defaults to browser/worker conditions only | Unit tests of serialization utilities without jest customExportConditions | Scripts that precompute static payloads
Related errors
- The React Server cannot be used outside a react-server envir
- Use react-server-dom-webpack/client instead.
- Use react-server-dom-webpack/client instead.
- The React Server Writer cannot be used outside a react-serve
- The React Server cannot be used outside a react-server envir
AI-assisted analysis of facebook/react@eafeac097b (2026-08-21).
Data as JSON: /api/errors/36e5077545cc3423.
Report an issue: GitHub.