{"record":{"id":"6cb970dc7ff57188","repo":"facebook/react","slug":"cannot-have-both-use-client-and-use-server-dir-6cb970","errorCode":null,"errorMessage":"Cannot have both \"use client\" and \"use server\" directives in the same file.","messagePattern":"Cannot have both \"use client\" and \"use server\" directives in the same file\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/react-server-dom-unbundled/src/ReactFlightUnbundledNodeRegister.js","lineNumber":70,"sourceCode":"    for (let i = 0; i < body.length; i++) {\n      const node = body[i];\n      if (node.type !== 'ExpressionStatement' || !node.directive) {\n        break;\n      }\n      if (node.directive === 'use client') {\n        useClient = true;\n      }\n      if (node.directive === 'use server') {\n        useServer = true;\n      }\n    }\n\n    if (!useClient && !useServer) {\n      return originalCompile.apply(this, arguments);\n    }\n\n    if (useClient && useServer) {\n      throw new Error(\n        'Cannot have both \"use client\" and \"use server\" directives in the same file.',\n      );\n    }\n\n    if (useClient) {\n      const moduleId: string = url.pathToFileURL(filename).href as any;\n      this.exports = createClientModuleProxy(moduleId);\n    }\n\n    if (useServer) {\n      originalCompile.apply(this, arguments);\n\n      const moduleId: string = url.pathToFileURL(filename).href as any;\n\n      const exports = this.exports;\n\n      // This module is imported server to server, but opts in to exposing functions by\n      // reference. If there are any functions in the export.","sourceCodeStart":52,"sourceCodeEnd":88,"githubUrl":"https://github.com/facebook/react/blob/eafeac097ba51e1eab809c07102126bd5f8e5425/packages/react-server-dom-unbundled/src/ReactFlightUnbundledNodeRegister.js#L52-L88","documentation":"react-server-dom-unbundled's node-register hook wraps module.compile to detect RSC directives. After scanning the parsed AST it rejects files that declare both 'use client' and 'use server': a module cannot simultaneously be a client boundary (exports proxied to the browser) and a server boundary (exports registered as server functions), so the hook throws before compiling.","triggerScenarios":"A module compiled through `module.register(...)` / the unbundled node-register hook whose leading directives contain both \"use client\" and \"use server\".","commonSituations":"Adding a server action to an existing client component file instead of a new module; tutorial code merged incorrectly so both directive lines survive; codemods that prepend a directive without removing the existing one.","solutions":["Move server actions (\"use server\") into their own file and import them from the client component.","Remove whichever directive does not match the file's intended boundary.","Add a lint/CI check that rejects files containing both directive strings."],"exampleFix":"// before: one file, both directives\n\"use client\";\n\"use server\";\nexport default function App() {}\n\n// after\n// app.js (\"use client\") imports { save } from './actions.js' (\"use server\")\n\"use client\";\nimport { save } from './actions';\nexport default function App() {}","handlingStrategy":"validation","validationCode":"// Lint rule (no-restricted-syntax style) or script check before register()\nconst src = fs.readFileSync(filename, 'utf8');\nif (/^[\"']use client[\"']/m.test(src) && /^[\"']use server[\"']/m.test(src)) {\n  throw new Error(`${filename}: split \"use client\" and \"use server\" into separate files`);\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["One boundary per file: components in 'use client' files, actions in 'use server' files.","Add the pre-compile scan so the error surfaces in CI with a filename.","Avoid codemods that prepend directives; set them deliberately."],"tags":["rsc","react-server-components","use-client","use-server","directives","node-register","unbundled"],"backgroundTag":"rsc-dual-directives-conflict","analyzedSha":"eafeac097ba51e1eab809c07102126bd5f8e5425","analyzedAt":"2026-08-21T22:01:08.818Z","schemaVersion":2},"datasetVersion":"2026-08-22T04:17:13.399Z"}