Next.js Discord

Discord Forum

Error: Element type is invalid: expected a string (for built-in components) or a class/function (for

Unanswered
Taiwan Dog posted this in #help-forum
Open in Discord
Taiwan DogOP
Getting error Error: Element type is invalid: expected a string (for built-in components) or a class/function (for composite components) but got: undefined. when running pnpm build && pnpm start with Next.js 14.2.0
I do not get this error when running pnpm dev.

34 Replies

im using as={Element}
Check that... That's most likely the problem case
Taiwan DogOP
uh oh :C
thats gonna be fun
Well, you're gonna be busy for the next hour
Taiwan DogOP
thanks
im going to try commenting out all these and see if they get solved
You can narrow down the results to the parts where you change the as property dynamically
Or where you are using as={Component} where the component came from some other file (missing import)
Taiwan DogOP
it worked in previous versions :(
ok that didnt really help
@Riday πŸ’™ Or where you are using as={Component} where the component came from some other file (missing import)
Taiwan DogOP
i'm using eslint so i dont think i have a missing import
@Taiwan Dog what do you mean by dynamically?
Uh, changing the as property based on some conditions
Taiwan DogOP
like {something ? </> : null}?
this might be something that has to be fixed in the ui component library
that i'm using
doing this did get rid of the issue
@Taiwan Dog doing this did get rid of the issue
What did you change here?
@Taiwan Dog ok that didnt really help
Taiwan DogOP
i've removed the providers and script tags related to the ui component library
oh
i see where the issue is
          <ColorModeScript
            type="cookie"
            nonce="testing"
            initialColorMode="system"
          />
was causing the issue
removing this gets rid of the error
Oh
Taiwan DogOP
hmm without this the page will always render as light mode first even if set to dark mode :(
Taiwan DogOP
ok its not ideal but i decided to get cookies from layout.tsx and use that instead of the script
above does not work with theme "system"