Next.js Discord

Discord Forum

md files not working

Answered
Common House-Martin posted this in #help-forum
Open in Discord
Common House-MartinOP
Hello, I'm trying to setup .md files and I followed all the steps on the docs but it doesn't work
I'll provide pics of my file tree, my next.config, the mdx-components.tsx file, the error and the .md file
Answered by American Crow
View full answer

10 Replies

Common House-MartinOP
Common House-MartinOP
anyone?
Common House-MartinOP
any kind soul?
@Common House-Martin any kind soul?
American Crow
Let me spin up my testing env and give it a quick try. Which docs did you follow, these https://nextjs.org/docs/app/building-your-application/configuring/mdx#install-dependencies ?
@Common House-Martin yes
American Crow
Okay i got it setup.
Running into the same error.
Renaming / Using mdx instead of .md for /mdx-page/page.mdx "fixes" the issue.
Don't really know why mdx does get picked up but md does not.
@American Crow Okay i got it setup. Running into the same error. Renaming / Using mdx instead of .md for `/mdx-page/page.mdx` "fixes" the issue. Don't really know why mdx does get picked up but md does not.
Common House-MartinOP
ok .mdx kind of works can you try applying a style to the h1 to see if it changes? I tried it but it doesn't take the changes in style
import type { MDXComponents } from 'mdx/types'
import Image, { ImageProps } from 'next/image'

// This file allows you to provide custom React components
// to be used in MDX files. You can import and use any
// React component you want, including inline styles,
// components from other libraries, and more.

export function useMDXComponents(components: MDXComponents): MDXComponents {
    return {
        // Allows customizing built-in components, e.g. to add styling.
        h1: ({ children }) => (
            <h1 style={{ color: 'red', fontSize: '48px' }}>{children}</h1>
        ),
        img: (props) => (
            <Image
                sizes="100vw"
                style={{ width: '100%', height: 'auto' }}
                {...(props as ImageProps)}
            />
        ),
        ...components,
    }
}
this is the mdx-components.tsx
American Crow
Answer
Common House-MartinOP
oh nice, solved then, thanks