Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot access logger.error on the server due to client module import #2

Open
pawvan opened this issue Sep 2, 2024 · 0 comments
Open

Comments

@pawvan
Copy link
Owner

pawvan commented Sep 2, 2024

Description:
I encountered an issue with the following code in my Next.js application:

tsx
Copy code
import { getServerSession } from "next-auth";
import { authConfig } from "@/lib/auth";
import { redirect } from "next/navigation";
import { CredentialsForm } from "@/components/credentialsForm";
import { GoogleSignInButton, GithubSignInButton } from "@/components/authButtons";

export default async function SignInPage() {
const session = await getServerSession(authConfig);

console.log("Session: ", session); // Error triggered here

if (session) return redirect("/page-1");

return (



Sign In





Or




);
}
Error Message:

vbnet
Copy code
Error: Cannot access logger.error on the server. You cannot dot into a client module from a server component. You can only pass the imported name through.
Steps to Reproduce:

Use console.log or similar logging functions in a server component.
Import client modules or components in the same server component.
Expected Behavior:

console.log should work without error in the server component, or Next.js should provide a clearer way to debug server-side code without causing import issues.

Actual Behavior:

The code triggers an error because console.log is being used in a server component where client-side imports or code are being mixed.

Additional Information:

Next.js version: [v20.16.0]
Node.js version: [14.2.7]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant