Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Directives fails but work with "@next/mdx" #444

Open
hsjobeki opened this issue Mar 6, 2024 · 3 comments
Open

Directives fails but work with "@next/mdx" #444

hsjobeki opened this issue Mar 6, 2024 · 3 comments

Comments

@hsjobeki
Copy link

hsjobeki commented Mar 6, 2024

Some remark / rehype plugins fail unexpectedly with next-mdx-remote, while they dont fail with nextMDX

In my concrete example "remark-directive" works with nextMDX but fails with next-mdx-remote

Also reading the troubleshooting page didn't help any further: https://mdxjs.com/docs/troubleshooting-mdx/

Works ✔️

<!-- Test.md -->
:::note{.warn}
stuff
:::

Trying to compile it with next-mdx-remote 🟥

const src = `
:::note{.warn}
stuff
:::
`;

const MDX = () => (
 <MDXRemote
   options={{
     mdxOptions: {
       remarkPlugins: [remarkDirective],
     },
   }}
   source={src}
 />
);

Produces the following error message.

More information: https://mdxjs.com/docs/troubleshooting-mdx]
 ⨯ [Error: [next-mdx-remote] error compiling MDX:
Cannot set properties of undefined (setting 'directiveAttributes')

More information: https://mdxjs.com/docs/troubleshooting-mdx] {
  digest: '3365904784'
}

While compiling the same source with mdx from @next/mdx is just fine.

// next.config.mjs
import mdx from "@next/mdx";
import remarkDirective from "remark-directive";

const withMDX = mdx({
  options: {
    remarkPlugins: [remarkDirective],
  },
});

export default withMDX({});

I dont understand whats the difference here. I would be very pleased if somebody helped me figure this out. 🙏

@hsjobeki hsjobeki changed the title Unexpected plugin failures Plugin fails which work with "@next/mdx" but not with "next-mdx-remote" Mar 6, 2024
@hsjobeki hsjobeki changed the title Plugin fails which work with "@next/mdx" but not with "next-mdx-remote" Directives fails but work with "@next/mdx" Mar 6, 2024
@talatkuyuk
Copy link

The next-mdx-remote uses the @mdx-js/mdx version 2, but @next/mdx uses version 3, which both depends on different version of unified.

So, for now, remark-directive@2 is compatible with the next-mdx-remote, remark-directive@3 is compatible with the @next/mdx

With this regard you should employ [email protected] for the next-mdx-remote, I suppose.

@hsjobeki
Copy link
Author

hsjobeki commented Mar 6, 2024

The next-mdx-remote uses the @mdx-js/mdx version 2, but @next/mdx uses version 3, which both depends on different version > of unified.

Thanks i didn't know where the difference came from.
I guess this will be fixed by #425

@talatkuyuk
Copy link

Hi @hsjobeki, next-mdx-remote v5 is now compatible with MDX ver.3. Can you check the issue again, and close it, if it is resolved.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants