I have a basic blog post I receive from GraphCMS:
export async function getStaticProps({ params }) {
const { event } = await graphcms.request('query here', { slug: params.slug });
return {
props: {
event,
},
revalidate: 2,
};
The RichText content received from GraphCMS gets displayed, as well as revalidated by using the markdown directly: {event.about.markdown}
. The problem is when I introduce MDXRemote. By simply just importing
import { serialize } from "next-mdx-remote/serialize";
and not using it, I get:
./node_modules/@babel/core/lib/transformation/normalize-file.js:9:0
Module not found: Can't resolve 'fs'
null
The above-mentioned error gets displayed no matter what I do, except if I set mdxSource in getStaticProps:
if (event.about) {
event.mdxSource = await serialize(event.about.markdown);
}
This removes the module not found error, and correctly converts the markdown to mdx locally, but after pushing it to vercel, any changes done to any portion of the blog post (title, date, content markdown) in GraphCMS won't get displayed.
I've tried serializing in useEffect, but as previously stated, any place but getStaticProps result in Module not found: Can't resolve 'fs'
. What would be the correct way to serialize markdown so it gets revalidated from GraphCMS at each refresh?