You are attempting to export "metadata" from a component marked with "use client"
Last verified:
The fix
You are attempting to export "metadata" from a component marked with "use client", which is disallowed. Remove the directive from that file, or move the export. Metadata belongs on a Server Component.
- 1
Keep metadata in a server file
Remove
"use client"from the layout or page that exportsmetadataorgenerateMetadata. Leave the export there. Do not replace it with a<title>written fromuseEffect.import type { Metadata } from "next"; import { ThemeProvider } from "./theme-provider"; export const metadata: Metadata = { title: "Acme", }; export default function RootLayout({ children, }: { children: React.ReactNode; }) { return ( <html lang="en"> <body> <ThemeProvider>{children}</ThemeProvider> </body> </html> ); } - 2
Move the hooks into a child
The provider file starts with
"use client"and renderschildren. The layout imports it and stays a Server Component. Do not pass a click handler from the layout into that provider. That is the functions page. - 3
Follow the import trace when this file has no directive
If
layout.tsxorpage.tsxhas no"use client"and the error still names it, a client module imports this file. Stop exportingmetadatathrough that client barrel. Keep the export in the server layout, and import the client child one way. - 4
Do the same for generateMetadata
An async
generateMetadatastays in the server file next to the page. Do not move it into the client component that renders the form.paramsin that function is a Promise on current Next.js. Await it. That is the params page if the error changes to that sentence.
Why it happens
Next.js only allows the metadata object and generateMetadata on a Server Component. The build throws You are attempting to export "metadata" from a component marked with "use client", which is disallowed. Either remove the export, or the "use client" directive. generateMetadata gets the same sentence with that name in the quotes.
Generated layouts put "use client" on app/layout.tsx so a provider can call useState, then also export metadata. The file cannot be both. Importing a Client Component into a server layout does not make the layout a Client Component. The directive in the layout file does. A client file that re-exports the page, or a barrel that pulls the layout into a client module, makes the same export illegal even when you do not see the directive on the line the overlay highlights. The import trace names that client file.
The next error you'll probably hit
Once this is fixed, the usual follow-up is useState only works in a Client Component. useState only works in a Client Component. This Next.js file is a Server Component until the first line is use client. Add that, or move the hook.
Prompt to paste back into your AI tool
Paste this above the error.
Next.js throws: You are attempting to export "metadata" from a component marked with "use client", which is disallowed. If it names generateMetadata, quote that. The file is <file>. The import trace is: <paste> Do not add a <title> from useEffect to replace the metadata export. Do not put "use client" on the root layout. Do not export metadata from the client provider. 1. Remove "use client" from the file that exports metadata or generateMetadata. 2. Move hooks and providers into a child whose first line is "use client", and render children there. 3. If this file has no directive, stop the client module from importing it. Keep the export on the server layout or page. 4. Change only those files.
Common questions
+The layout does not say use client, and the build still names metadata. Why?
A client file imports this module, so the export is in the client graph. The import trace names that file. Keep metadata in a server layout that the client file does not import.
+Can I set the title in the client provider instead?
No. The metadata export is the App Router API, and it has to stay on a Server Component. A document.title write in an effect does not replace it and runs too late for the initial HTML.
Related errors
- useState only works in a Client ComponentuseState only works in a Client Component. This Next.js file is a Server Component until the first line is use client. Add that, or move the hook.Cursorv0BoltNext.jsReactNov 11, 2026
- Functions cannot be passed directly to Client ComponentsFunctions cannot be passed directly to Client Components unless you explicitly expose it by marking it with "use server". An onClick in a Server Component is the other sentence: Event handlers cannot be passed to Client Component props. Define UI handlers in the client file.Cursorv0BoltNext.jsReactOct 27, 2026
- params is a Promise and must be unwrappedparams is a Promise and must be unwrapped in Next.js 16. await params before use. Do not cast it, and do not add use client just to read it in sync.Cursorv0BoltNext.jsReactOct 20, 2026
- ReferenceError: window is not definedwindow is not defined: Next.js read window, document, or localStorage on the server. Move that read into useEffect, or load the widget with ssr: false.Cursorv0BoltNext.jsReactOct 14, 2026