facebook/react · error
The React Server cannot be used outside a react-server envir
Error message
The React Server cannot be used outside a react-server environment. You must configure Node.js using the `--conditions react-server` flag.
What it means
The source-level server entry of react-server-dom-esm: importing the server module outside a react-server environment throws at module load. The server writer only resolves under the 'react-server' export condition; in any other condition the module graph intentionally fails fast with instructions to configure Node with --conditions react-server. This keeps server-only code from ever executing in a client bundle or plain Node process.
Source
Thrown at packages/react-server-dom-esm/server.js:10
/**
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @flow
*/
throw new Error(
'The React Server 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 the server with node --conditions react-server
- Add 'react-server' to resolve conditions for the server build, and ensure the client build never imports the server entry
- For Jest, set NODE_OPTIONS='--conditions react-server' for server-side test projects
- Split shared code so the server entry is only reachable from server-only modules
Example fix
// before
// package.json
"scripts": { "start": "node server.js" }
// after
"scripts": { "start": "node --conditions react-server server.js" } Defensive patterns
Strategy: validation
Validate before calling
const hasReactServerCondition =
process.execArgv.some(a => a.includes('react-server'));
if (!hasReactServerCondition) {
console.error('Run with: node --conditions react-server');
process.exit(1);
} Prevention
- Put node --conditions react-server in the package.json start script
- Keep server-only imports in files only the server graph can reach
- Set NODE_OPTIONS='--conditions react-server' for server-side jest projects
When it happens
Trigger: importing 'react-server-dom-esm/server' (renderToPipeableStream and friends) in plain Node without the react-server condition; a client bundle graph that transitively reaches the server entry; tooling (bundler, test runner) resolving without custom conditions so the throwing module is selected.
Common situations: RSC servers started without the documented flag; shared modules imported by both client and server where the server import leaks into the client graph; CI running server code through runners that reset NODE_OPTIONS.
Related errors
- 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
- 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/178bfa8a4ca0b6d7.
Report an issue: GitHub.