Skip to content

content/index.mdx won't load in app/page.tsx but will /app/[[...mdxPath]]/page.tsx #4764

@willmruzek

Description

@willmruzek

Describe the bug

importPage() or importPage([]) doesn't work when in app/page.tsx but does in app/[[...mdxPath]].

I would expect both to work.

I'd prefer to use app/page.tsx to give me the ability to use index.md and add / specific elements/styling.

To Reproduce

  1. Add index.mdx

./content/index.mdx

---
title: Some title
---

Some index content
  1. Add index page.tsx

./src/app/page.tsx

import { importPage } from 'nextra/pages';
import { useMDXComponents as getMDXComponents } from '@/mdx-components';

// @ts-expect-error -- Issue with nextra-theme-blog
const Wrapper = getMDXComponents().wrapper;

export default async function SiteIndexPage(props) {
  const { default: MDXContent, toc, metadata } = await importPage([]);

  return (
    <Wrapper toc={toc} metadata={metadata}>
      <MDXContent {...props} />
    </Wrapper>
  );
}
  1. Attempt to load localhost:3000

I see a 404 page with the following error logged:

- error [nextra] Error while loading { pathSegments: [] } Error: Cannot find module 'private-next-content-dir/undefined'
    at async SiteIndexPage (src/app/page.tsx:8:49)
   6 |
   7 | export default async function SiteIndexPage(props) {
>  8 |   const { default: MDXContent, toc, metadata } = await importPage([]);
     |                                                 ^
   9 |
  10 |   return (
  11 |     <Wrapper toc={toc} metadata={metadata}> {
  code: 'MODULE_NOT_FOUND'
}
  1. Remove app/page.tsx and add app/[[...mdxPage]]/page.tsx

./src/app/[[...mdxPath]]/page.tsx (same as app/page.tsx)

import { importPage } from 'nextra/pages';
import { useMDXComponents as getMDXComponents } from '@/mdx-components';

// @ts-expect-error -- Issue with nextra-theme-blog
const Wrapper = getMDXComponents().wrapper;

export default async function SiteIndexPage(props) {
  const { default: MDXContent, toc, metadata } = await importPage([]);

  return (
    <Wrapper toc={toc} metadata={metadata}>
      <MDXContent {...props} />
    </Wrapper>
  );
}

It works!

Expected behavior A clear and concise description of what you expected to
happen.

I would expect both app/page.tsx and app/[[...mdxPath]]/page.tsx to load content/index.md.

Screenshots If applicable, add screenshots to help explain your problem.

Desktop (please complete the following information):

  • OS: MacOS 15.6 (24G84)
  • Browser: Chrome 138.0.7204.184
  • Node: 22.18.0
  • Next.js: 15.4.5
  • Nextra: 4.3.0
  • nextra-theme-blog: 4.3.0

Thanks!

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions