facebook/react · error · 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

react-server-dom-webpack/server.js is the default (non-react-server) branch of the './server' export: when Node's module resolution does not have the 'react-server' condition active, this stub throws on import. It protects the Flight server implementation from being loaded into a client or plain Node context where its bundler-manifest expectations make no sense.

Source

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

  1. Keep server imports out of shared modules; import 'react-server-dom-webpack/client' in browser code
  2. Run the server with node --conditions react-server and configure bundler conditionNames/test conditions with 'react-server'
  3. Grep the client bundle output for 'react-server-dom-webpack/server' to find the offending import

Example fix

// before: shared module imports server entry unconditionally
import {renderToPipeableStream} from 'react-server-dom-webpack/server';

// after: only the server bundle (built with conditions: ['react-server']) imports it,
// client bundle imports the client entry
import {createFromReadableStream} from 'react-server-dom-webpack/client';
Defensive patterns

Strategy: validation

Validate before calling

// keep client and server imports in separate files; assert at build time
// webpack client config resolve aliases to catch accidents:
resolve: {alias: {'react-server-dom-webpack/server': false}}

Prevention

When it happens

Trigger: import ... from 'react-server-dom-webpack/server' executed without --conditions react-server; a bundler compiling this module into a browser bundle (no react-server conditionName).

Common situations: Accidentally importing the server entry from shared/client code | Dev servers/proxies that bundle server files for HMR without the condition | Missing condition in jest/ts-node/bun configurations

Related errors


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