Unsupported Server Component type: undefined / next js 13

I ran into some weird behavior in Next js 13 while trying to do a simple action. I have prepared the most simple example showing the problem. I hope you can help me figure out why this is happening.

There are 3 components.

page:

import {Container} from '../components/Container' export default function index() { return ( <Container> <Container.Window> <h1>12345</h1> </Container.Window> </Container> ) } 

Container:

'use client'; import { Window } from './Window'; export const Container = ({ children }) => { return children; }; Container.Window = Window; 

Window:

"use client"; export const Window = ({children})=>{ return children } 

Page server component. The Container and Window components are client-side. Container imports and exports Window.

I am getting this error:

"Unsupported Server Component type: undefined"

  • Import the Window component separately.
    Works, no errors

  • Make the Container component a server component.
    Works, no errors

  • Make the page component client-side.
    Works, no errors

But I think the first option is the most convenient. Would love to make it work

- example

4 Answers

I had the same issue. I was able to fix by changing the named export to a default export, and importing without the braces.

Try changing:

export const Window = ({children})=>{ 

to

const Window = ({children})=>{ ... } export default Window; 

Hopin that helps!

1

Update (for named imports)

As per Jason Frank's comments, you can keep the 'use client' at the component level without the need to mark all components as client side in the index.ts. This allows you to keep using named imports whilst keeping a folder of mixed server/client components.

// Client Side Component 'use client' export default function ClientCard() { return <p>client side card here</p> } 
// Server Side Component export default function ServerCard() { return <p>server side card here</p> } 
// index.ts export { default as ClientCard } from './client-card'; export { default as ServerCard } from './server-card'; 

Not too sure if this is related but ran into a similar issue.

'use client' export function Card() { return <p>card here</p> } 
// index.ts export * from './card' 

The above threw errors when attempting to import via import { Card } from './card.

Adding 'use client' to the index.ts seemed to fix the issue.

// index.ts - FIXED 'use client' export * from './card' 
3

I had this return jsx:

return <>{product && <ProductView product={product} />}</>; 

it turns out that importing one component inside ProductView was from the wrong path.

If you are exporting your component as default export and are importing your component as a individual export or vice versa, this could also be the scenario where the problem occurs

Importing and Exporting error like this:

exported component:

export default function ExportedComp() { //logic } 

Page where you import:

import {ExportedComp} from 'pathname' 

Or vice versa!

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

You Might Also Like