Invalid default exports in layout.tsx
Answered
Barbary Lion posted this in #help-forum
Barbary LionOP
src/app/layout.tsx
Type error: Layout "src/app/layout.tsx" has an invalid "default" export:
Type "{ children: ReactNode; session: Session | null; }" is not valid.
Next.js build worker exited with code: 1 and signal: null
ELIFECYCLE Command failed with exit code 1.
Error: Command "pnpm run vercel-build" exited with 1
Merged branch to production which built successfully in Vercel preview. Layout.tsx WAS NOT changed in this branch. Any clue on this? Are my default exports deprecated?
Layout.tsx:
export default function RootLayout({
children,
session,
}: {
children: React.ReactNode;
session: Session | null;
}) {
return (
<html className="scroll-smooth">
<body className="text-black">
<TRPCReactProvider>
<SessionProvider session={session}>
<Navigation />
<main className="flex min-h-screen flex-col items-center justify-center">
{children}
</main>
<Footer />
<AnalyticsRedacted />
<SpeedInsightsRedacted />
</SessionProvider>
</TRPCReactProvider>
</body>
</html>
);
}
Answered by Asian black bear
There is no workaround - layouts are a framework feature and must strictly adhere to the signature the framework expects. Your custom
session
prop will not be populated by Next.5 Replies
Barbary LionOP
I don't want to make my RootLayout server only/dynamic with async, what is the secondary route to solve this?
Thanks a bunch in advance :-P
Asian black bear
There is no workaround - layouts are a framework feature and must strictly adhere to the signature the framework expects. Your custom
session
prop will not be populated by Next.Answer
Barbary LionOP
Thank you. Could you then point me to a direction how to implement checking the user session in a optimal manner in Next without utilizing the additional prop?
Asian black bear
It depends which library you use for that. Typically a check in the middleware in addition to pages and route handlers (but not in layouts) is the way to go.