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

npm/static.js is the condition-less fallback for the static-rendering entry of react-server-dom-unbundled. Static generation uses the same Flight writer as streaming SSR and equally requires the react-server environment; when the condition is missing, Node resolves to this stub which throws immediately with the required flag rather than rendering with the wrong react build.

Source

Thrown at packages/react-server-dom-unbundled/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

  1. Start the static-rendering process with `node --conditions react-server script.js`.
  2. Add the condition to bundler/resolve config when the static entry is bundled at build time.
  3. For tests, add 'react-server' to the runner's export conditions.
  4. Verify process.execArgv in the failing process to confirm the flag is present.

Example fix

# before
"build": "node prerender.js"

# after
"build": "node --conditions react-server prerender.js"
Defensive patterns

Strategy: validation

Validate before calling

if (!process.execArgv.some(a => a.includes('react-server'))) {
  throw new Error('Static rendering requires: node --conditions react-server');
}

Prevention

When it happens

Trigger: Importing react-server-dom-unbundled/static (e.g. renderToReadableStream for static/prerender use) in Node without `--conditions react-server`.

Common situations: Prerender scripts or static-site generation CLIs run with plain `node`; build tooling that spawns Node without forwarding NODE_OPTIONS; test setups with default conditions.

Related errors


AI-assisted analysis of facebook/react@eafeac097b (2026-08-21). Data as JSON: /api/errors/9a9e199b2c23bb0c. Report an issue: GitHub.