{"record":{"id":"36e5077545cc3423","repo":"facebook/react","slug":"the-react-server-writer-cannot-be-used-outside-a-r-36e507","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":"Error","httpStatus":null,"severity":"error","filePath":"packages/react-server-dom-webpack/npm/static.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-webpack/npm/static.js#L1-L7","documentation":"The published static entry (npm/static.js) is the default (non-react-server) fallback for './static'. The real static APIs — the synchronous/static Flight writer used for edgeless or fully-buffered serialization — are only served under the 'react-server' export condition; without it this guard throws 'The React Server Writer cannot be used outside a react-server environment.'","triggerScenarios":"Importing react-server-dom-webpack/static (e.g. for the static writer used in edge-light/workerd runtimes or tests) without the react-server condition being set in the resolver.","commonSituations":"Workerd/Cloudflare Workers builds where the bundler defaults to browser/worker conditions only | Unit tests of serialization utilities without jest customExportConditions | Scripts that precompute static payloads","solutions":["Add 'react-server' to the runtime's resolve conditions (wrangler/esbuild build conditions, webpack conditionNames)","In tests, set testEnvironmentOptions.customExportConditions = ['node', 'react-server'] or the runner's equivalent","Run plain Node scripts with --conditions react-server"],"exampleFix":"// before (esbuild)\nesbuild.build({entryPoints: ['worker.js'], conditions: ['worker']});\n\n// after\nesbuild.build({entryPoints: ['worker.js'], conditions: ['worker', 'react-server']});","handlingStrategy":"validation","validationCode":"// esbuild/vite SSR: assert the condition is configured before build\nconst buildOpts = {conditions: ['node', 'import', 'react-server']};\nif (!buildOpts.conditions.includes('react-server')) throw new Error('add react-server to conditions');","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Keep the server bundle's conditionNames list in one shared config constant","Test-build the server entry in CI to catch missing conditions","Document the required conditions next to the runtime target"],"tags":["react-server-components","webpack","package-exports","conditions","edge"],"backgroundTag":"missing-react-server-condition","analyzedSha":"eafeac097ba51e1eab809c07102126bd5f8e5425","analyzedAt":"2026-08-21T22:01:08.818Z","schemaVersion":2},"datasetVersion":"2026-08-21T23:17:16.201Z"}