facebook/react · 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
react-server-dom-esm/npm/server.js is the default-condition stub for the server subpath in the published package. The real server implementation only resolves when Node activates the 'react-server' export condition (package.json maps the subpath under that condition); without it, Node falls back to this stub, which throws with the exact remedy in the message: run Node with --conditions react-server.
Source
Thrown at packages/react-server-dom-esm/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
- Start Node with the condition: node --conditions react-server server.js
- For bundlers, add 'react-server' to resolve.conditions in the server build only (webpack 5 resolve.conditions)
- For tests, set NODE_OPTIONS='--conditions react-server' or map the subpath to the .react-server.js artifact in jest moduleNameMapper
- Make sure only server code imports this subpath — client code belongs on react-server-dom-esm/client
Example fix
# before $ node server.js # throws: ...configure Node.js using the `--conditions react-server` flag # after $ node --conditions react-server server.js
Defensive patterns
Strategy: validation
Validate before calling
// fail fast if the react-server condition is not active
if (!process.execArgv.some(a => a.includes('react-server'))) {
throw new Error('Start this process with: node --conditions react-server');
} Prevention
- Bake --conditions react-server into the start script so the flag is never forgotten
- Add 'react-server' to resolve.conditions only for server bundles
- Keep server imports of this subpath out of client graphs (lint boundaries)
When it happens
Trigger: require/import 'react-server-dom-esm/server' (directly or transitively) in a plain `node app.js` process started without --conditions react-server; a client-side bundle accidentally importing the server entry; bundler or test-runner resolve configurations that drop the react-server condition.
Common situations: Running the RSC server without the documented Node flag; webpack/vite server builds missing 'react-server' in resolve.conditions; Jest resolving the stub because its module resolution ignores custom conditions.
Related errors
- The React Server cannot be used outside a react-server envir
- The React Server cannot be used outside a react-server envir
- The React Server Writer cannot be used outside a react-serve
- The React Server cannot be used outside a react-server envir
- The React Server Writer cannot be used outside a react-serve
AI-assisted analysis of facebook/react@eafeac097b (2026-08-21).
Data as JSON: /api/errors/c9260d15e803aaf5.
Report an issue: GitHub.