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 server entry (npm/server.js) is the non-react-server fallback for './server': the exports map only serves the real server implementation when the 'react-server' condition is active. This copy targets the Writer APIs, so its message says 'React Server Writer' — importing it without the condition throws immediately, telling you Node was not configured for the server environment.

Source

Thrown at packages/react-server-dom-webpack/npm/server.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. Run Node with --conditions react-server (scripts entry: "start": "node --conditions react-server server.js")
  2. Add 'react-server' to the server bundler's resolve.conditionNames / esbuild conditions
  3. Verify NODE_OPTIONS propagates in CI, Docker CMD, and process managers

Example fix

# before
CMD ["node", "server.js"]

# after
CMD ["node", "--conditions", "react-server", "server.js"]
Defensive patterns

Strategy: validation

Validate before calling

const ok = process.execArgv.join(' ').includes('react-server') ||
  (process.env.NODE_OPTIONS || '').includes('--conditions react-server');
if (!ok) process.exitCode = 1; // refuse to boot without the condition

Prevention

When it happens

Trigger: require/import of react-server-dom-webpack/server in Node without --conditions react-server; bundling the server entry with a bundler whose resolve conditions omit 'react-server'.

Common situations: node server.js run scripts missing the condition flag | Bundlers (webpack/esbuild/vite SSR) without conditionNames including 'react-server' | CI or production runners that strip NODE_OPTIONS

Related errors


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