{"record":{"id":"53b0b12eb8e7b937","repo":"facebook/react","slug":"cannot-assign-to-a-client-module-from-a-server-mod","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-turbopack/src/ReactFlightTurbopackReferences.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-turbopack/src/ReactFlightTurbopackReferences.js#L186-L222","documentation":"The set trap of the deep proxy covering nested client references: client references are opaque read-only handles, so mutating an export of a client module from server code throws instead of silently writing into client scope the server cannot see.","triggerScenarios":"`const chart = ClientModule.Chart; chart.theme = 'dark';` — assigning a property on a reference obtained by dotting into a 'use client' module from server code.","commonSituations":"Monkey-patching a client helper from a server module; shared code that configures libraries imported across the boundary; decorators applied to client exports.","solutions":["Move the mutation into client code (an event handler, effect, or module init inside the 'use client' file)","If it is configuration, pass it as props/arguments to the client component instead of assigning","Keep mutable shared state in a proper store both sides import by value/props"],"exampleFix":"// before (server module)\nimport * as Editor from './editor-client';\nEditor.config.plugins = [myPlugin]; // Error: cannot assign\n\n// after (client component)\n'use client';\nimport {config} from './editor-client';\nfunction EditorHost({plugin}) {\n  useEffect(() => { config.plugins = [plugin]; }, [plugin]);\n  return <Editor />;\n}","handlingStrategy":"type-guard","validationCode":null,"typeGuard":"const CLIENT_REFERENCE = Symbol.for('react.client.reference');\nfunction isClientReference(value) {\n  return value != null && (typeof value === 'object' || typeof value === 'function') && value.$$typeof === CLIENT_REFERENCE;\n}\n// guard any configure() helper:\nfunction configure(target, props) {\n  if (isClientReference(target)) {\n    throw new Error('Configure client modules from client code, via props');\n  }\n  Object.assign(target, props);\n}","tryCatchPattern":null,"preventionTips":["Do all mutation of client-module exports inside 'use client' code","Pass configuration as props or arguments","Keep setup/config files side-aware"],"tags":["react-server-components","turbopack","client-references","use-client","mutation"],"backgroundTag":"rsc-client-server-boundary","analyzedSha":"eafeac097ba51e1eab809c07102126bd5f8e5425","analyzedAt":"2026-08-21T22:01:08.818Z","schemaVersion":2},"datasetVersion":"2026-08-22T04:17:13.399Z"}