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-turbopack/static.js is the fallback entry Node resolves when the react-server export condition is NOT active. React's server bundles depend on that condition to swap in the react-server build of react (the one whose client APIs throw); loading the server/static writer without it would pull in the wrong react, so the module throws immediately at import time with the fix in the message.

Source

Thrown at packages/react-server-dom-turbopack/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 condition: `node --conditions react-server server.js` (or add it to NODE_OPTIONS / your start script).
  2. For jest set `customExportConditions: ['react-server']` in react-server test environments; for vitest add `resolve.conditions: ['react-server']` in the server project config.
  3. Ensure bundlers that resolve the server bundle (webpack/turbopack for the server) include 'react-server' in resolve conditions.
  4. Verify with `node -p "process.execArgv"` that the flag actually reaches the process that imports the package.

Example fix

// before
"scripts": { "start": "node server.js" }

// after
"scripts": { "start": "node --conditions react-server server.js" }
Defensive patterns

Strategy: validation

Validate before calling

// Check before importing the server entry
const hasReactServerCondition =
  process.execArgv.some(a => a.includes('react-server')) ||
  (process.env.NODE_OPTIONS || '').includes('react-server');
if (!hasReactServerCondition) {
  throw new Error('Start Node with --conditions react-server before loading the Flight server');
}

Prevention

When it happens

Trigger: Importing react-server-dom-turbopack/static (or /server, which re-exports it) in a Node process that was started without `--conditions react-server`, e.g. `node server.js`, a custom server script, or a test runner with default export conditions.

Common situations: Custom Node servers or SSR scripts run without the flag; vitest/jest resolving the package with default conditions; tools that spawn node without forwarding NODE_OPTIONS; upgrading a setup where the flag used to be set in a now-ignored env file.

Related errors


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