{"record":{"id":"d2b0e98bb28a2de4","repo":"facebook/react","slug":"attempted-to-call-name-from-the-server-but-d2b0e9","errorCode":null,"errorMessage":"Attempted to call ${name}() from the server but ${name} is on the client. It's not possible to invoke a client function from the server, it can only be rendered as a Component or passed to props of a Client Component.","messagePattern":"Attempted to call (.+?)\\(\\) from the server but (.+?) is on the client\\. It's not possible to invoke a client function from the server, it can only be rendered as a Component or passed to props of a Client Component\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/react-server-dom-unbundled/src/ReactFlightUnbundledNodeLoader.js","lineNumber":607,"sourceCode":"  for (let i = 0; i < names.length; i++) {\n    const name = names[i];\n    if (name === 'default') {\n      newSrc += 'export default ';\n      newSrc += 'registerClientReference(function() {';\n      newSrc +=\n        'throw new Error(' +\n        JSON.stringify(\n          `Attempted to call the default export of ${url} from the server ` +\n            `but it's on the client. It's not possible to invoke a client function from ` +\n            `the server, it can only be rendered as a Component or passed to props of a ` +\n            `Client Component.`,\n        ) +\n        ');';\n    } else {\n      newSrc += 'export const ' + name + ' = ';\n      newSrc += 'registerClientReference(function() {';\n      newSrc +=\n        'throw new Error(' +\n        JSON.stringify(\n          `Attempted to call ${name}() from the server but ${name} is on the client. ` +\n            `It's not possible to invoke a client function from the server, it can ` +\n            `only be rendered as a Component or passed to props of a Client Component.`,\n        ) +\n        ');';\n    }\n    newSrc += '},';\n    newSrc += JSON.stringify(url) + ',';\n    newSrc += JSON.stringify(name) + ');\\n';\n  }\n\n  // TODO: Generate source maps for Client Reference functions so they can point to their\n  // original locations.\n  return newSrc;\n}\n\nasync function loadClientImport(","sourceCodeStart":589,"sourceCodeEnd":625,"githubUrl":"https://github.com/facebook/react/blob/eafeac097ba51e1eab809c07102126bd5f8e5425/packages/react-server-dom-unbundled/src/ReactFlightUnbundledNodeLoader.js#L589-L625","documentation":"The unbundled Node loader rewrites every named export of a 'use client' module into a registered client reference whose function body throws. Calling a named export from server code triggers it: client functions can never execute on the server — they may only be rendered as Components or forwarded as props to Client Components so the browser runs them.","triggerScenarios":"Server code does `import { getUserName } from './user.client'; getUserName(id)` — invoking a named export of a 'use client' module as a function on the server.","commonSituations":"Shared utility barrels marked 'use client' whose functions are called in server components; event-handler/validate helpers defined in client files and reused on the server; calling a client component factory function instead of rendering its result in JSX.","solutions":["Move pure helpers into a shared module without the 'use client' directive and import it from both server and client.","If the work must run in the browser, relocate the call into a client component and pass plain data over the boundary.","If the export is a component, render it (<Card/>) rather than calling Card()."],"exampleFix":"// before (server component)\nimport { getUserName } from './lib/user.client';\nconst name = getUserName(user.id);\n\n// after: lib/user.js has no 'use client' directive\nimport { getUserName } from './lib/user';\nconst name = getUserName(user.id);","handlingStrategy":"type-guard","validationCode":"if (isClientReference(getUserName)) {\n  throw new Error('getUserName lives on the client - move it to a shared module');\n}","typeGuard":"const CLIENT_REFERENCE_TAG = Symbol.for('react.client.reference');\nexport function isClientReference(value) {\n  return typeof value === 'function' && value.$$typeof === CLIENT_REFERENCE_TAG;\n}","tryCatchPattern":null,"preventionTips":["Audit files that gained 'use client' for exports still called from server code.","Split shared helpers out of client files before adding the directive.","Render components; call only functions from directive-free modules."],"tags":["rsc","react-server-components","client-boundary","server-components","unbundled","node-loader"],"backgroundTag":"rsc-client-function-called-from-server","analyzedSha":"eafeac097ba51e1eab809c07102126bd5f8e5425","analyzedAt":"2026-08-21T22:01:08.818Z","schemaVersion":2},"datasetVersion":"2026-08-21T23:17:16.201Z"}