{"record":{"id":"b9e6694216ceb8e1","repo":"vercel/next.js","slug":"name-is-only-available-in-a-server-component","errorCode":null,"errorMessage":"`${name}` is only available in a Server Component.","messagePattern":"`(.+?)` is only available in a Server Component\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/next/cache.js","lineNumber":6,"sourceCode":"let cacheExports\n\nif (process.env.NEXT_RUNTIME === '') {\n  const notAvailableInClient = (name) => {\n    return function notAvailable() {\n      throw new Error(`\\`${name}\\` is only available in a Server Component.`)\n    }\n  }\n\n  cacheExports = {\n    unstable_cache: function unstable_cache(cb) {\n      // Legacy behavior: allow importing/using unstable_cache from client bundles\n      // without pulling in server internals.\n      if (typeof cb !== 'function') return cb\n      return function cached() {\n        return cb.apply(this, arguments)\n      }\n    },\n    unstable_noStore: function unstable_noStore() {},\n    io: require('next/dist/client/request/io.browser').io,\n\n    updateTag: notAvailableInClient('updateTag'),\n    revalidateTag: notAvailableInClient('revalidateTag'),\n    revalidatePath: notAvailableInClient('revalidatePath'),","sourceCodeStart":1,"sourceCodeEnd":24,"githubUrl":"https://github.com/vercel/next.js/blob/0ae8c72462952df163f1b1e0726641bc5b40dc93/packages/next/cache.js#L1-L24","documentation":"Next.js ships a client-bundle stub for `next/cache` (active when `NEXT_RUNTIME === ''`) that throws this error for server-only functions: revalidateTag, revalidatePath, updateTag, refresh, cacheLife, and cacheTag. These functions manipulate server-side cache state and cannot run in the browser. The stub prevents client components from accidentally invoking server cache APIs.","triggerScenarios":"Importing `revalidateTag`, `revalidatePath`, `cacheLife`, `cacheTag`, `refresh`, or `updateTag` from `next/cache` and calling it in code that ends up in the client bundle — a Client Component, a module imported by one, or a file without a 'use server' directive.","commonSituations":"Moving cache invalidation logic into a shared utility that gets imported by a Client Component; calling revalidateTag in an onClick handler; importing from next/cache in a file missing 'use server'; refactoring that pulls server code into a client-imported module.","solutions":["Move the cache function call into a Server Component, Server Action ('use server'), or Route Handler.","Add 'use server' at the top of the file or function that calls the cache API.","Split shared utilities into separate server-only and client-safe modules.","Call the cache function via a server action invoked from the client component."],"exampleFix":"// before — called in a Client Component\n'use client'\nimport { revalidateTag } from 'next/cache'\nfunction Button() {\n  return <button onClick={() => revalidateTag('posts')}>Refresh</button>\n}\n\n// after — move to a Server Action\n// actions.ts\n'use server'\nimport { revalidateTag } from 'next/cache'\nexport async function refreshPosts() { revalidateTag('posts') }\n// ClientComponent.tsx\n'use client'\nimport { refreshPosts } from './actions'\nfunction Button() {\n  return <button onClick={() => refreshPosts()}>Refresh</button>\n}","handlingStrategy":"validation","validationCode":"// Ensure cache functions are only called in server contexts.\n// The simplest guard: check if the file/module is in the server bundle.\nfunction assertServerContext(fnName: string): void {\n  if (typeof window !== 'undefined') {\n    throw new Error(`${fnName} must not be called in client code. Use a Server Action.`)\n  }\n}","typeGuard":"// Type-level: use 'use server' on functions that call cache APIs\n// so they can't be inlined into client bundles.\n// Runtime guard for shared modules:\nfunction isServerSide(): boolean {\n  return typeof window === 'undefined' && typeof globalThis !== 'undefined'\n}","tryCatchPattern":null,"preventionTips":["Add 'use server' to any file or function that calls revalidateTag, revalidatePath, cacheLife, cacheTag, etc.","Never import from next/cache in a file with 'use client' or imported by a client component.","Keep server-only cache logic in dedicated server modules (Route Handlers, Server Actions).","Use the 'server-only' package to enforce server-only imports."],"tags":["cache","server-components","client-components","next-cache"],"analyzedSha":"0ae8c72462952df163f1b1e0726641bc5b40dc93","analyzedAt":"2026-08-06T19:44:29.143Z","schemaVersion":2},"datasetVersion":"2026-08-07T02:17:10.218Z"}