question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Next.js 13 - appDir - Error: Unsupported Server Component type: undefined

See original GitHub issue

Verify canary release

  • I verified that the issue exists in the latest Next.js canary release

Provide environment information

Operating System:
  Platform: win32
  Arch: x64
  Version: Windows 10 Pro for Workstations
Binaries:
  Node: 18.12.0
  npm: N/A
  Yarn: N/A
  pnpm: N/A
Relevant packages:
  next: 13.0.0
  eslint-config-next: N/A
  react: 18.2.0
  react-dom: 18.2.0

What browser are you using? (if relevant)

Chrome 106.0.5249.119 / Firefox Developer Edition 107.0b5

How are you deploying your application? (if relevant)

next start, Vercel (https://test-next-13-appdir.vercel.app/)

Describe the Bug

This issue only appears in dev mode

When I import a client component (the file has “use client” directive) from its exact location (let’s say ./src/components/Foo/Bar.tsx) and then use it in appDir, everything works fine, the component loads and there’s no issue.

But when I reexport it in ./src/components/Foo/index.ts with export * from "./Bar" and then import it in appDir like this: import { Bar } from "@/components", suddenly appDir stops working and then Next shows an issue like this: Error: Unsupported Server Component type: undefined (https://ibb.co/y01RPBv). I tried console.logging the component and what was logged is just undefined. The production build doesn’t have anything of the sort though, everything works just fine.

Thank you 😃

Expected Behavior

Everything should work just fine, the component should display as normal.

Link to reproduction

https://github.com/DuCanhGH/next-13-server-component-undefined

To Reproduce

  • Run pnpm i
  • Run pnpm dev
  • Go to http://localhost:3000 and it should fail to load the page. I find it to be reproducible on both Chrome and Firefox

Issue Analytics

  • State:open
  • Created a year ago
  • Reactions:6
  • Comments:18 (9 by maintainers)

github_iconTop GitHub Comments

3reactions
DuCanhGHcommented, Oct 27, 2022

@awareness481 it really did, doesn’t seem to be neat, but it works for now 😄

3reactions
awareness481commented, Oct 27, 2022

This is “solved” if you add the "use client" directive to the top export (src/components/index.ts in this case).

Read more comments on GitHub >

github_iconTop Results From Across the Web

TypeError: unsupported file type: undefined after update to v ...
It works now as of next@v11.0.1 . No need to follow the steps below. Disable the static images feature for now as a...
Read more >
[Feedback] App Directory in Next.js 13 #41745 - GitHub
This discussion is where you can provide feedback on the new conventions and features around layouts, server components, streaming, and more.
Read more >
Blog - Next.js 13
Next.js 13 introduces layouts, React Server Components, and streaming in the app directory, as well as Turbopack, an improved image ...
Read more >
What's New in Next.js 13 - AppSignal Blog
It supports Server Components, TypeScript, JSX, CSS, and more. As the project is in alpha state, many of the features are not yet...
Read more >
Next.js 13: Working with the new app directory - LogRocket Blog
Mandatory root layout; Head tag; Route groups; Server components. Hands-on with Next.js 13. Project creation; The page and layout file ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found