Next.js Discord

Discord Forum

'use client' directive getting error

Unanswered
Perro de Pastor Mallorquin posted this in #help-forum
Open in Discord
Perro de Pastor MallorquinOP
This is my code:

'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 (
#Unknown Channel
{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>
);
})}
</>
);
}

12 Replies

Perro de Pastor MallorquinOP
This is the error message:
✓ Compiled /_not-found in 1682ms (807 modules)
⚠ Fast Refresh had to perform a full reload due to a runtime error.
GET /_next/static/webpack/20e8361f62447367.webpack.hot-update.json 404 in 1958ms
Warning: React.jsx: type is invalid -- expected a string (for built-in components) or a class/function (for composite components) but got: undefined. You likely forgot to export your component from the file it's defined in, or you might have mixed up default and named imports.
Warning: React.jsx: type is invalid -- expected a string (for built-in components) or a class/function (for composite components) but got: undefined. You likely forgot to export your component from the file it's defined in, or you might have mixed up default and named imports.
⨯ Error: Unsupported Server Component type: undefined
at stringify (<anonymous>)
at stringify (<anonymous>)
digest: "1227705133"
⨯ Error: Unsupported Server Component type: undefined
at stringify (<anonymous>)
at stringify (<anonymous>)
digest: "1227705133"
GET /dashboard/customers 500 in 145ms
Velvet ant
where do you use NavLinks component ?
and also you can use backticks for code sharing.
dont know if there is a command to show that
French Lop
I'm getting the same error and this is for the next.js starter tutorial at this point: https://nextjs.org/learn/dashboard-app/navigating-between-pages#pattern-showing-active-links
from commenting/uncommenting bits of the code added in this section it is clear that the issue is with the
'use client';
line of code.
my only suggestion would be to terminate the dev server, remove the .next folder and rerun npm run dev again
the bug looks very weird so probably due to the content of the .next folder being corrupted somehow
French Lop
Well now I'm getting this error.
@French Lop Well now I'm getting this error.
you are probably using lowercase <link> which is wrong. it should be <Link> with the import statement import Link from 'next/link'; at the top.
French Lop
that did it thanks!
@joulev my only suggestion would be to terminate the dev server, remove the `.next` folder and rerun `npm run dev` again
cc OP @Perro de Pastor Mallorquin in case you haven't fixed the error yourself yet