Build failed when adding custom remark/rehype plugin
See original GitHub issuemdx-bundler
version: 6.0.1node
version: 14.17.0npm
version: 6.14.13esbuild
version: 0.12.25platform
: windows 11
Relevant code or config
async function getFileRenderBySlug(type: string, slug: string) {
const file_path = path.join(BLOG_FOLDER_PATH, type, `${slug}.mdx`);
if (checkIfPathExists(file_path) === false) {
throw new Error(`${file_path} file not found`);
}
const mdxSource = fs.readFileSync(file_path, "utf8");
if (process.platform === "win32") {
process.env.ESBUILD_BINARY_PATH = path.join(
ROOT,
"node_modules",
"esbuild",
"esbuild.exe"
);
} else {
process.env.ESBUILD_BINARY_PATH = path.join(
ROOT,
"node_modules",
"esbuild",
"bin",
"esbuild"
);
}
const result = await bundleMDX(mdxSource, {
cwd: path.join(ROOT, COMPONENTS),
xdmOptions(options) {
options.remarkPlugins = [
...(options.remarkPlugins ?? []),
// if I remove this plugins it builds without any issue
remarkGfm,
remarkToc,
remarkMath,
];
options.rehypePlugins = [
...(options.rehypePlugins ?? []),
// if I remove this plugins it builds without any issue
rehypePrism,
rehypeKatex,
];
return options;
},
});
const { code, frontmatter } = result;
return {
toRender: code,
data: {
readingTime: readingTime(code),
...(frontmatter as MarkdownFrontMatter),
},
};
}
Error Output:
Server Error
Error: Build failed with 1 error:
_mdx_bundler_entry_point-1f92ed01-7bb4-4697-9847-570c4c57cf02.mdx:0:0: error: [plugin: esbuild-xdm]
This error happened while generating the page. Any console logs will be displayed in the terminal window.
Call Stack
failureErrorWithLog
file:///E:/projects/next-ts-blog-starter/node_modules/esbuild/lib/main.js (1478:15)
<unknown>
file:///E:/projects/next-ts-blog-starter/node_modules/esbuild/lib/main.js (1136:28)
runOnEndCallbacks
file:///E:/projects/next-ts-blog-starter/node_modules/esbuild/lib/main.js (926:63)
buildResponseToResult
file:///E:/projects/next-ts-blog-starter/node_modules/esbuild/lib/main.js (1134:7)
<unknown>
file:///E:/projects/next-ts-blog-starter/node_modules/esbuild/lib/main.js (1243:14)
<unknown>
file:///E:/projects/next-ts-blog-starter/node_modules/esbuild/lib/main.js (614:9)
handleIncomingPacket
file:///E:/projects/next-ts-blog-starter/node_modules/esbuild/lib/main.js (711:9)
Socket.readFromStdout
file:///E:/projects/next-ts-blog-starter/node_modules/esbuild/lib/main.js (581:7)
Socket.emit
events.js (376:20)
Socket.emit
domain.js (470:12)
When I am adding my custom remark/rehype plugins, it fails to build. But if I remove all my custom remark/rehype plugins it builds without any issue. Don’t know where I am doing wrong.
Currently moved to next-mdx-remote
😅
Issue Analytics
- State:
- Created 2 years ago
- Reactions:2
- Comments:20
Top Results From Across the Web
Transforming Markdown with Remark & Rehype - ryanfiller.com
Writing custom plugins to give extra powers to Markdown syntax using the Unified ecosystem.
Read more >Can't require remark and rehype plugins for gatsby-plugin-mdx
However upon running gatsby develop I encouter the following error: Error: [ERR_REQUIRE_ESM]: Must use import to load ES Module: C:\Users\User\ ...
Read more >rehype-remark - npm
This is a rehype plugin that transforms hast into mdast to support remark. When should I use this? This project is useful when...
Read more >gatsby-transformer-remark
This plugin adds additional fields to the MarkdownRemark GraphQL type including html , excerpt , headings , etc. Other Gatsby plugins can also...
Read more >Why I moved to Next.js | Saying goodbye to Gatsby
The plugins for remark and rehype can be used directly, I'm not waiting for a plugin author to add support. Everything else outside...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@wooorm 🤦♂️ I figured it out. I forgot to change to named exports for my unified dependencies:
I had this:
I needed this:
Such a small detail that I completely overlooked it. Thank you again for your help, your patience, and for all the awesome work you do!
Yeah, this error getting swallowed up somewhere made it really hard to debug this. But anyway, I think we can close this issue now!