{"record":{"id":"c9260d15e803aaf5","repo":"facebook/react","slug":"the-react-server-writer-cannot-be-used-outside-a-r","errorCode":null,"errorMessage":"The React Server Writer cannot be used outside a react-server environment. You must configure Node.js using the `--conditions react-server` flag.","messagePattern":"The React Server Writer cannot be used outside a react-server environment\\. You must configure Node\\.js using the `--conditions react-server` flag\\.","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/react-server-dom-esm/npm/server.js","lineNumber":3,"sourceCode":"'use strict';\n\nthrow new Error(\n  'The React Server Writer cannot be used outside a react-server environment. ' +\n    'You must configure Node.js using the `--conditions react-server` flag.'\n);\n","sourceCodeStart":1,"sourceCodeEnd":7,"githubUrl":"https://github.com/facebook/react/blob/eafeac097ba51e1eab809c07102126bd5f8e5425/packages/react-server-dom-esm/npm/server.js#L1-L7","documentation":"react-server-dom-esm/npm/server.js is the default-condition stub for the server subpath in the published package. The real server implementation only resolves when Node activates the 'react-server' export condition (package.json maps the subpath under that condition); without it, Node falls back to this stub, which throws with the exact remedy in the message: run Node with --conditions react-server.","triggerScenarios":"require/import 'react-server-dom-esm/server' (directly or transitively) in a plain `node app.js` process started without --conditions react-server; a client-side bundle accidentally importing the server entry; bundler or test-runner resolve configurations that drop the react-server condition.","commonSituations":"Running the RSC server without the documented Node flag; webpack/vite server builds missing 'react-server' in resolve.conditions; Jest resolving the stub because its module resolution ignores custom conditions.","solutions":["Start Node with the condition: node --conditions react-server server.js","For bundlers, add 'react-server' to resolve.conditions in the server build only (webpack 5 resolve.conditions)","For tests, set NODE_OPTIONS='--conditions react-server' or map the subpath to the .react-server.js artifact in jest moduleNameMapper","Make sure only server code imports this subpath — client code belongs on react-server-dom-esm/client"],"exampleFix":"# before\n$ node server.js # throws: ...configure Node.js using the `--conditions react-server` flag\n\n# after\n$ node --conditions react-server server.js","handlingStrategy":"validation","validationCode":"// fail fast if the react-server condition is not active\nif (!process.execArgv.some(a => a.includes('react-server'))) {\n  throw new Error('Start this process with: node --conditions react-server');\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Bake --conditions react-server into the start script so the flag is never forgotten","Add 'react-server' to resolve.conditions only for server bundles","Keep server imports of this subpath out of client graphs (lint boundaries)"],"tags":["react-server-components","node","export-conditions","environment"],"backgroundTag":"missing-react-server-condition","analyzedSha":"eafeac097ba51e1eab809c07102126bd5f8e5425","analyzedAt":"2026-08-21T22:01:08.818Z","schemaVersion":2},"datasetVersion":"2026-08-21T23:17:16.201Z"}