Skip to content
Sandesh Thapa
Writing

· 5 min read

Debugging React Server Components when a component is undefined

Fix “Unsupported Server Component type: undefined,” combine a server-rendered child with a client wrapper, and diagnose common import, prop, and browser API mistakes.

Frontend Developer at AITC International

  • react
  • javascript
  • nextjs
  • debugging

You add a button to an otherwise working page. The next render fails with Unsupported Server Component type: undefined. Before moving the page into a "use client" file, look at the name immediately after the opening angle bracket. In <NotesPanel />, React needs the value of NotesPanel to tell it what to render. An undefined value there can break the page even when the server/client split is exactly right.

There's a documented example from Next.js 13. A Server Component imported a name that a client module didn't export. The browser showed the error above. The development server's terminal pointed to the JSX line and suggested checking the import. Your toolchain may catch the missing export at build time or report an invalid element type instead. Original Next.js error report

Start with the import

Suppose the panel file declares export default function NotesPanel(). Which import gives the page that function?

import { NotesPanel } from "./NotesPanel"
import NotesPanel from "./NotesPanel"
Check your answer

The second line imports the default export. The first asks for a named export called NotesPanel. Naming the function in a default export helps with debugging, but the module still exports it under the name default.

Follow the import all the way to the defining file. A folder's index.js can change the public name. For example, export { default as NotesPanel } from "./NotesPanel" makes import { NotesPanel } from "./ui" valid, even though the component file uses a default export. If importing directly from the file works, inspect the index before changing any directives. React's guide to component imports and exports

If the error happens for only one kind of note, check the lookup that selects its component. With const View = views[note.kind], an unexpected kind can make <View /> fail while every import is correct. Inspect the failing kind and the keys in views. Add the missing renderer, or deliberately render a fallback if unknown kinds are valid input. An optional prop such as subtitle={undefined} is a different case: React can transport that value. It's the element type that matters here. React's supported prop values

How do I put server content inside a client panel?

Here's a three-file example for the Next.js App Router. The route supplies the contents, the panel controls visibility, and the list can later acquire a server-side data source. Start with fixed notes so you can verify the imports and the button before introducing a database.

app/notes/page.jsx
import NotesPanel from "./NotesPanel"
import { NoteList } from "./NoteList"

export default function NotesPage() {
  return (
    <main>
      <h1>Release notes</h1>
      <NotesPanel>
        <NoteList />
      </NotesPanel>
    </main>
  )
}
app/notes/NoteList.jsx
export function NoteList() {
  return (
    <ul>
      <li>Drafts now survive a page refresh.</li>
      <li>Search includes archived notes.</li>
    </ul>
  )
}
app/notes/NotesPanel.jsx
"use client"

import { useState } from "react"

export default function NotesPanel({ children }) {
  const [open, setOpen] = useState(false)
  return (
    <section>
      <button aria-expanded={open} onClick={() => setOpen(!open)}>
        {open ? "Hide notes" : "Show notes"}
      </button>
      {open && children}
    </section>
  )
}

Open /notes and press Show notes. Which component runs again? The click updates NotesPanel. The server parent already supplied <NoteList /> as its child, so the browser can reveal the list without requesting it. If you replace the two lines with an expensive database query, hiding the panel won't defer that query. To fetch on first open, make opening the panel initiate a request. Next.js composition examples

Four mistakes that need different fixes

What you observe What to inspect What to change
Adding a toggle produces a hook error Which module calls useState? Put the state and click handler in the client panel. Keep the page and list on the server.
A render prop fails when it crosses the boundary Does the server pass renderNotes={() => <NoteList />}? Pass the JSX as children or a named prop such as content={<NoteList />}. The panel can render that value directly.
Importing the list from the panel causes a server-only module error Follow the imports from the file marked "use client" down to the data reader. Have the server page import the list and supply its element. In Next.js, adding import "server-only" to the data module makes accidental client imports fail at build time.
A full reload throws window is not defined, even with "use client" Check for browser globals in module scope or during the initial render. Client Components can also be rendered on the server to produce initial HTML. Read the browser API in an event handler if a gesture needs it, or after mount in an effect if the UI must synchronize with it. Give the initial render a value both environments can produce.

An ordinary callback is fine between two components already in the client graph. Crossing from the server changes what React must transport. A Server Function is a special case: React can send a reference that the client calls to perform a server operation. That makes sense for Save note. A local state update is enough for Show notes. React's client boundary reference · Server Functions

What if the broken component comes from a library?

First verify the documented export for the package version you installed. If the export exists and the error points to a client hook inside the library, give that widget a small client entry point. For example, a local file can start with "use client" and re-export the package's documented widget. Import that local entry from the server page. This keeps the client boundary around the widget. If the package reads window during module initialization, also check its SSR instructions: a client entry can still participate in the initial HTML render. Next.js guidance for third-party components

When a page has several nested components, try rendering <section><NoteList /></section> in the page. Then try <NotesPanel>Test note</NotesPanel>. These two small substitutions tell you whether to inspect the list, the panel, or the values crossing between them. To follow those values through React's renderer, try the interactive Flight and Suspense walkthrough.