Error: Unsupported Server Component type: undefined (Dashboard tutorial - Chapter 5)
Answered
Brown bear posted this in #help-forum
Brown bearOP
I'm following tutorial from the official website and I got error on chapter five.
This is the file that cause the error, but I don't know which line actually:
This is the file that cause the error, but I don't know which line actually:
"use client";
import {
UserGroupIcon,
HomeIcon,
DocumentDuplicateIcon,
} from "@heroicons/react/24/outline";
import Link from "next/link";
import { usePathname } from "next/navigation";
import clsx from "clsx";
// Map of links to display in the side navigation.
// Depending on the size of the application, this would be stored in a database.
const links = [
{ name: "Home", href: "/dashboard", icon: HomeIcon },
{
name: "Invoices",
href: "/dashboard/invoices",
icon: DocumentDuplicateIcon,
},
{ name: "Customers", href: "/dashboard/customers", icon: UserGroupIcon },
];
export default function NavLinks() {
const pathName = usePathname();
return (
<>
{links.map((link) => {
const LinkIcon = link.icon;
return (
<Link
key={link.name}
href={link.href}
className={clsx(
"flex h-[48px] grow items-center justify-center gap-2 rounded-md bg-gray-50 p-3 text-sm font-medium hover:bg-sky-100 hover:text-blue-600 md:flex-none md:justify-start md:p-2 md:px-3",
{
"bg-sky-100 text-blue-600": pathName === link.href,
}
)}
>
<LinkIcon className="w-6" />
<p className="hidden md:block">{link.name}</p>
</Link>
);
})}
</>
);
}Answered by joulev
Try using a named export (export function NavLinks) instead. In the main file, import { NavLinks } from …
7 Replies
@joulev Try using a named export (export function NavLinks) instead. In the main file, import { NavLinks } from …
Brown bearOP
It works! thanks. Can you explain what happened? Or maybe just a link to a doc that I can dig it myself
@Brown bear It works! thanks. Can you explain what happened? Or maybe just a link to a doc that I can dig it myself
No clues what happened. It was probably a bug of nextjs. Your code should work, but it doesn’t - and seems like named exports still work well
Brown bearOP
Apparently I'm not the first person that experience it. So I guess for the time being I think it's best to stick with named export while working with Next.js. Right?
Yeah I always use named exports where possible, it’s a personal rule that predates this bug. I only use default exports when it’s required by the framework (e.g. export default function Page)
@joulev Yeah I always use named exports where possible, it’s a personal rule that predates this bug. I only use default exports when it’s required by the framework (e.g. export default function Page)
Brown bearOP
I see. So it's like convention in React?
Nope just a personal rule