nextra icon indicating copy to clipboard operation
nextra copied to clipboard

setup documentation does not works

Open alexisvisco opened this issue 6 months ago • 2 comments

I would love to use nextra but despite following the documentation I am facing an error :

Build Error

Module not found: Can't resolve 'next-mdx-import-source-file'

./node_modules/nextra/dist/client/setup-page.js (3:1)

Module not found: Can't resolve 'next-mdx-import-source-file'
  1 | "use no memo";
  2 | import { jsx } from "react/jsx-runtime";
> 3 | import { useMDXComponents as getMDXComponents } from "next-mdx-import-source-file";
    | ^
  4 | import { createElement } from "react";
  5 | const Wrapper = getMDXComponents().wrapper;
  6 | function HOC_MDXWrapper(MDXContent, hocProps) {

https://nextjs.org/docs/messages/module-not-found

Import trace for requested module:
./app/page.mdx
Image

i think there is something missing but since I don't know what I cannot use your library.

alexisvisco avatar Jun 13 '25 06:06 alexisvisco

where do you put mdx-components file?

dimaMachina avatar Jun 13 '25 10:06 dimaMachina

With nextjs version 15.5.2 i had the same issue. I moved the mdx-components.tsx into the root dir, still the same error.

The error came from my app/docs/[[...mdxPath]]/page.jsx. The import was import { useMDXComponents } from "@/mdx-components";

I created a JS shim in root dir mdx-components.js and added export { useMDXComponents } from './mdx-components.tsx'; This seems to help to resolve the correct file.

Then i changed the import in app/docs/[[...mdxPath]]/page.jsx from: import { useMDXComponents } from "@/mdx-components";

to: import { useMDXComponents } from 'next-mdx-import-source-file';

This worked for me to fix this error.

lpj-app avatar Oct 10 '25 20:10 lpj-app