Closed bwkam closed 1 year ago
Your problem is related to Next.js, not MDX.
You are trying to use server side data in a Next.js page. To get this data, you need to use either getStaticProps
or getServerSideProps
.
Your MDX file:
<ReadingTime readingTime={props.readingTime} />
export function getStaticProps() {
return {
props: {
readingTime: getReadingTime("post-1")
}
}
}
Ah, my bad, that was so simple, thanks! 😅
Initial checklist
Affected packages and versions
I don't know what's that
Link to runnable example
No response
Steps to reproduce
Create a blog directory at
pages
, and inside create an mdx file. Then write some markdown and insert<ReadingTime readTime=getReadingTime("post-1")
where post-1 is the name of the mdx file.And that's the definition of
getReadingTime()
And that's
<ReadingTime />
Expected behavior
getReadTime()
should normally return the read time and get passed without any issues as a prop to<ReadingTime />
and finally gets rendered.Actual behavior
TypeError: fs__WEBPACK_IMPORTED_MODULE_0___default(...).readdirSync is not a function
<ReadingTime readTime=getReadingTime("post-1")
^ That's what I have in my mdx fileRuntime
Node v19
Package manager
npm v8
OS
Linux
Build and bundle tools
Next.js