Skip to content

@next/mdx - import() breaks .mdx files in development #77554

@fullyherge

Description

@fullyherge

Link to the code that reproduces this issue

https://github.com/fullyherge/next-mdx-import-repro/blob/main/src/app/page.tsx

To Reproduce

  1. Run the application locally (npm run dev)
  2. Get error
 ⨯ TypeError: Cannot read properties of undefined (reading 'A')
    at _createMdxContent (webpack-internal:///(rsc)/./src/app/stuff.mdx:15:73)
    at MDXContent (webpack-internal:///(rsc)/./src/app/stuff.mdx:37:16) {
  digest: '4239156248'
}

Changing to import Stuff from "stuff.mdx" works fine, but my use case in existing application that I just updated to Next 15 and React 19 is to import all .mdx files from a certain folder, via require.context.
It works fine in production builds.

Current vs. Expected behavior

Importing .mdx file via import() gives an error.
Expected behaviour is for it to work, like import x from does.

Provide environment information

Operating System:
  Platform: darwin
  Arch: arm64
  Version: Darwin Kernel Version 24.3.0: Thu Jan  2 20:24:23 PST 2025; root:xnu-11215.81.4~3/RELEASE_ARM64_T6020
  Available memory (MB): 16384
  Available CPU cores: 10
Binaries:
  Node: 20.18.2
  npm: 11.1.0
  Yarn: 1.22.22
  pnpm: N/A
Relevant Packages:
  next: 15.2.4 // Latest available version is detected (15.2.4).
  eslint-config-next: 15.2.4
  react: 19.0.0
  react-dom: 19.0.0
  typescript: 5.8.2
Next.js Config:
  output: N/A

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

Markdown (MDX)

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

next dev (local)

Additional context

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    Markdown (MDX)Related to Markdown with Next.js.

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions