kentcdodds / mdx-bundler

🦤 Give me MDX/TSX strings and I'll give you back a component you can render. Supports imports!
MIT License
1.78k stars 75 forks source link

Can't import react components #189

Closed spcbfr closed 2 years ago

spcbfr commented 2 years ago

Relevant code or config

export async function getPostData(id) {
  const fullPath = path.join(postsDirectory, `${id}.mdx`);
  const fileContents = fs.readFileSync(fullPath, 'utf8');

  // Use gray-matter to parse the post metadata section
  const matterResult = matter(fileContents);

  const processedContent = await remark()
    .use(html)
    .process(matterResult.content);
  const contentHtml = processedContent.toString();
  // Combine the data with the id
  const {code, frontmatter} = await bundleMDX({
    source: fileContents,
  })
  return {
    id,
    code,
    frontmatter,
  };
}

What you did: tried to import a react component into my mdx file

What happened: I got this errror

The JSX syntax extension is not currently enabled

Reproduction repository: https://github.com/spcbfr/nextjs-blog go to an mdx file and try to import a react component from the components directory

spcbfr commented 2 years ago

Fixed, had to change the extension of the components from .js to .jsx