{"record":{"id":"e26f88a53d0a7503","repo":"facebook/react","slug":"cannot-assign-to-a-client-module-from-a-server-mod-e26f88","errorCode":null,"errorMessage":"Cannot assign to a client module from a server module.","messagePattern":"Cannot assign to a client module from a server module\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/react-server-dom-unbundled/src/ReactFlightUnbundledReferences.js","lineNumber":204,"sourceCode":"        // This allows server components to render <ClientContext.Provider>\n        // which will be serialized and executed on the client.\n        return receiver;\n      case 'then':\n        throw new Error(\n          `Cannot await or return from a thenable. ` +\n            `You cannot await a client module from a server component.`,\n        );\n    }\n    // eslint-disable-next-line react-internal/safe-string-coercion\n    const expression = String(target.name) + '.' + String(name);\n    throw new Error(\n      `Cannot access ${expression} on the server. ` +\n        'You cannot dot into a client module from a server component. ' +\n        'You can only pass the imported name through.',\n    );\n  },\n  set: function () {\n    throw new Error('Cannot assign to a client module from a server module.');\n  },\n};\n\nfunction getReference(target: Function, name: string | symbol): $FlowFixMe {\n  switch (name) {\n    // These names are read by the Flight runtime if you end up using the exports object.\n    case '$$typeof':\n      return target.$$typeof;\n    case '$$id':\n      return target.$$id;\n    case '$$async':\n      return target.$$async;\n    case 'name':\n      return target.name;\n    // We need to special case this because createElement reads it if we pass this\n    // reference.\n    case 'defaultProps':\n      return undefined;","sourceCodeStart":186,"sourceCodeEnd":222,"githubUrl":"https://github.com/facebook/react/blob/eafeac097ba51e1eab809c07102126bd5f8e5425/packages/react-server-dom-unbundled/src/ReactFlightUnbundledReferences.js#L186-L222","documentation":"The deep proxy around each named export of a client module implements a throwing `set` trap. Server code cannot mutate a client reference: the value lives in the browser bundle, and assignment on the server would be silently lost. Any write to a property of a client export therefore throws immediately.","triggerScenarios":"In a server module: `clientExport.foo = value`, e.g. setting `Button.defaultProps`, monkey-patching a client utility, or `Object.assign(someClientExport, {...})` from server code.","commonSituations":"Configuring plugins/defaultProps on components that turned out to be client references; libraries that attach markers or cache onto imported functions; test setup files that stub exports of 'use client' modules while running in a server environment.","solutions":["Move the mutation into the client module itself (configure it where it runs, in the browser).","Pass configuration as props/arguments to the client component instead of mutating it from the server.","For test stubs, mock the module in the module graph (jest moduleNameMapper / vi.mock) rather than assigning to its exports."],"exampleFix":"// before (server code)\nimport Button from './Button.client';\nButton.defaultProps = { size: 'md' };\n\n// after\n<Button size=\"md\" {...props} />","handlingStrategy":"validation","validationCode":"// Guard mutations before they happen\nfunction assertNotClientReference(target) {\n  if (target != null && target.$$typeof === Symbol.for('react.client.reference')) {\n    throw new Error('Refusing to assign to a client reference');\n  }\n}\nassertNotClientReference(Button);","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Configure client components via props, never by mutating them from the server.","Stub client modules at resolution time in tests (vi.mock/jest.mock), not by assignment."],"tags":["rsc","react-server-components","client-boundary","mutation","proxy","unbundled"],"backgroundTag":"rsc-client-module-assignment","analyzedSha":"eafeac097ba51e1eab809c07102126bd5f8e5425","analyzedAt":"2026-08-21T22:01:08.818Z","schemaVersion":2},"datasetVersion":"2026-08-21T23:17:16.201Z"}