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-unbundled/static.js is the fallback entry for the package's './static' export when the 'react-server' Node condition is NOT active (see the exports map: './static' only resolves to real code under react-server). It exists so that accidentally importing the server/static runtime in an ordinary Node process fails immediately with instructions instead of mysteriously misbehaving.

Source

Thrown at packages/react-server-dom-unbundled/static.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. Start Node with the flag: node --conditions react-server server.js (or set NODE_OPTIONS='--conditions react-server')
  2. Add 'react-server' to your test runner conditions (jest: testEnvironmentOptions.customExportConditions) and to the server bundler's resolve.conditionNames
  3. Import the client entry instead if this file is actually client-side code

Example fix

# before
node server.js

# after
node --conditions react-server server.js
Defensive patterns

Strategy: validation

Validate before calling

// Fail with a clear message before the bad import happens
const hasCondition = process.execArgv.some(a => a.includes('react-server')) ||
  (process.env.NODE_OPTIONS || '').includes('react-server');
if (!hasCondition) throw new Error('start with: node --conditions react-server');
const rscStatic = await import('react-server-dom-unbundled/static');

Prevention

When it happens

Trigger: require/import of react-server-dom-unbundled/static (or an export path that falls through to it) in a Node process started without --conditions react-server; bundling server code without adding 'react-server' to the bundler's resolve conditions.

Common situations: Running node server.js, tests, or scripts that touch the server entry without the condition flag | Jest/vitest configs missing customExportConditions/conditions with 'react-server' | Webpack esbuild configs missing conditionNames: ['react-server'] for the server bundle

Related errors


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