Next.js Discord

Discord Forum

Prerender error:Error: Element type is invalid: expected a string (for built-in components)...

Unanswered
White-winged Scoter posted this in #help-forum
Open in Discord
White-winged ScoterOP
Error: Element type is invalid: expected a string (for built-in components) or a class/function (for composite components) but got: undefined.


Only happens >= 14.2.8

context: monorepo with a component library, using nextJS for the docs. I did a big refactor so I don't use dot notation components anymore, because those break when used in page or layout. And the docs build an run fine in up to 14.2.7.

The error usually means that an export somewhere is wrong (using default vs named), but this is what is happening:
When I'm importing a component from the library in layout.tsx it builds.

When I import a component within a component with use client in and use that component in layout.tsx it throws the error.

setting export const dynamic = 'force-dynamic' in layout.tsx everything builds.

From what I can tell, my exported esm and cjs modules look fine.

"use strict";
export { Accordion, AccordionContent, AccordionItem, AccordionTrigger } from './components/accordion.js';
export ...


repo: https://github.com/darenmalfait/nerdfishui

1 Reply

White-winged ScoterOP
For future reference:

I had this line in my next.config which was unused an causing the error

serverComponentsExternalPackages: ['@floating-ui/dom'],