Skip to content

Importing client components in MDX fails in dev mode #56153

Closed
@pomber

Description

@pomber

Link to the code that reproduces this issue

https://github.com/pomber/nextjs-mdx-use-client-bug

To Reproduce

  1. Start the app with next dev (it only happens in development mode)

Current vs. Expected behavior

Fails with this error:

Unhandled Runtime Error
Error: Cannot access Test.propTypes on the server. You cannot dot into a client module from a server component. You can only pass the imported name through.

Call Stack
Object.get
/workspace/nextjs-mdx-use-client-bug/node_modules/next/dist/compiled/next-server/app-page.runtime.dev.js (22:23981)
React
_createMdxContent
webpack-internal:///(rsc)/./app/hello.mdx (25:74)
MDXContent
webpack-internal:///(rsc)/./app/hello.mdx (45:16)
ej
/workspace/nextjs-mdx-use-client-bug/node_modules/next/dist/compiled/next-server/app-page.runtime.dev.js (22:35053)

Verify canary release

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

Provide environment information

$ npx --no-install next info

Operating System:
  Platform: linux
  Arch: x64
  Version: #202309200834 SMP PREEMPT_DYNAMIC Wed Sep 20 09:14:42 UTC 2023
Binaries:
  Node: 18.18.0
  npm: 9.8.1
  Yarn: 1.22.19
  pnpm: 8.7.6
Relevant Packages:
  next: 13.5.4-canary.4
  eslint-config-next: N/A
  react: 18.2.0
  react-dom: 18.2.0
  typescript: 5.1.3
Next.js Config:
  output: N/A

Which area(s) are affected? (Select all that apply)

App Router, MDX (@next/mdx)

Additional context

I'm having problems using any client component directly from mdx files:

import { Test } from "./test";

# Hello

<Test />

If ./test.js has "use client" this fails in dev mode.

A workaround is to re-export the Test component from a file without "use client".

The same example works with next@13.4.19 and fails with next@13.5.1.

Similar to #52415 but now in v13.5 it happens for every client component.

NEXT-1666

Metadata

Metadata

Assignees

No one assigned

    Labels

    Markdown (MDX)Related to Markdown with Next.js.bugIssue was opened via the bug report template.linear: nextConfirmed issue that is tracked by the Next.js team.locked

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions