Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

nextjs "Error: Unsupported Server Component type: undefined"

My code is like below

'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';
 
// ...
 
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>
        );
      })}
    </>
  );
}

why this error raised ? and how to solve it ?
(An error occurs when you try to 'use client;')

this code from nextjs official tutorail code :
https://nextjs.org/learn/dashboard-app/navigating-between-pages

Thank you.

like image 779
Kundera Avatar asked Sep 07 '25 19:09

Kundera


1 Answers

I encountered the same issue and managed to resolve it by changing the NavLinks component to a named export/import

export function NavLinks() {
  const pathname = usePathname();
  return (
  //...
  )
}

In sidenav.tsx,

import { NavLinks } from "@/app/ui/dashboard/nav-links";
like image 141
LAMEfreak Avatar answered Sep 09 '25 09:09

LAMEfreak