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/static.js is the non-react-server fallback of the './static' export. Like the server entry, it throws on evaluation unless Node resolved the specifier with the react-server condition, guaranteeing the static Flight renderer only runs in a react-server environment.

Source

Thrown at packages/react-server-dom-parcel/npm/static.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. Start the process with --conditions react-server
  2. Import the explicit 'react-server-dom-parcel/static.node' / 'static.edge' / 'static.browser' variant
  3. Keep react-server out of conditionNames for any browser/client bundle and in for server builds

Example fix

// before
node --experimental-modules build.mjs // imports react-server-dom-parcel/static

// after
node --conditions react-server build.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/static');
}

Try / catch

try {
  const staticRenderer = await import('react-server-dom-parcel/static');
} 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/static' without --conditions react-server; deep-importing the built static.js file; bundler resolving the default condition for code that pulls the static renderer.

Common situations: Forgetting the flag in dev/test/prod scripts; bundlers resolving the static entry for a client bundle; upgrading the package when the condition gates were introduced.

Related errors


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