Closed AlSirang closed 6 months ago
cloakSSROnlySecret
is only available from React Server Components. It seems like your root layout is a RSC, but does maybe some other file that contains a Client Component import something from it?
Try to add a import "server-only"
at the top of your RootLayout to see if that triggers - that would validate that you're not in a RSC.
I added import "server-only"
but it did nothing (no errors or warnings). I also removed all imports and only imported cloakSSROnlySecret
, but it is still giving me an error for the import.
RootLayout with all imports removed:
import 'server-only'
import { cookies } from 'next/headers'
import { cloakSSROnlySecret } from 'ssr-only-secrets'
import './globals.css'
export default function RootLayout({ children }: { children: React.ReactNode }) {
const sessionIdPlain = cookies().get('access_token')?.value
const sessionId = cloakSSROnlySecret(sessionIdPlain ?? '', 'SECRET_KEY')
return (
<html lang='en'>
<body>
{children}
</body>
</html>
)
}
I just created a brand new Next.js app, but it still gives me the error mentioned above.
Versions:
RootLayout.tsx
import type { Metadata } from "next";
import { Inter } from "next/font/google";
import "./globals.css";
import { cookies } from "next/headers";
// '"ssr-only-secrets"' has no exported member named 'cloakSSROnlySecret'. Did you mean 'readSSROnlySecret'?ts(2724)
import { cloakSSROnlySecret } from "ssr-only-secrets";
const inter = Inter({ subsets: ["latin"] });
export const metadata: Metadata = {
title: "Create Next App",
description: "Generated by create next app",
};
export default function RootLayout({
children,
}: {
children: React.ReactNode;
}) {
const sessionIdPlain = cookies().get("access_token")?.value;
const sessionId = cloakSSROnlySecret(sessionIdPlain ?? "", "SECRET_KEY");
return (
<html lang="en">
<body className={inter.className}>{children}</body>
</html>
);
}
Oh wait I just noticed, are they doing moduleResolution: "bundler"
now? While that's correct, it's also new. I'll have to adjust for that on a TS level. Thanks for the report!
This should be fixed in 0.1.2 now.
Thank you for the update. The error is fixed now.
When trying to import
cloakSSROnlySecret
in a Next.js server component, I am getting the following error:ssr-only-secrets has no exported member named cloakSSROnlySecret
Here is the component:
Versions:
I am using the Next.js app router, and the above code is from RootLayout. Do I need to configure something else to resolve this error? The cloakSSROnlySecret function works, but I'm getting an error when I import it.
tsconfig.json