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

npm/server.js is the non-react-server fallback of the './server' export. It evaluates to a throw so the Flight writer never runs outside a process resolved with the react-server condition; the real implementation sits behind the condition in package.json exports.

Source

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

  1. Run Node with --conditions react-server or set NODE_OPTIONS=--conditions react-server
  2. Import the explicit 'react-server-dom-parcel/server.node' / 'server.edge' / 'server.browser' entry that bypasses the gate
  3. Ensure your bundler resolves the server build with react-server in conditionNames

Example fix

// before
node server.mjs // imports 'react-server-dom-parcel/server' -> throws

// after
node --conditions react-server server.mjs
Defensive patterns

Strategy: validation

Validate before calling

const flags = process.execArgv.concat((process.env.NODE_OPTIONS || '').split(' '));
if (!flags.some(a => a.includes('react-server'))) {
  throw new Error('Start with --conditions react-server before loading react-server-dom-parcel/server');
}

Try / catch

try {
  const server = await import('react-server-dom-parcel/server');
} catch (e) {
  if (/react-server environment/.test(e.message)) {
    throw new Error('Restart with --conditions react-server');
  }
  throw e;
}

Prevention

When it happens

Trigger: Importing 'react-server-dom-parcel/server' in a Node process started without --conditions react-server; a bundler resolving the default condition for a server entry; running the npm build under a runtime that does not forward Node conditions.

Common situations: Forgetting the flag in scripts or PM2/systemd configs; serverless bundlers that inline the server entry without react-server in conditionNames; jest/custom runners ignoring conditions.

Related errors


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