question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

serialize() doesn't load remark/rehype plugins

See original GitHub issue

I’m trying to use KaTeX, but so far I have failed:

const source = await serialize("Hello *world* and $1+1=2$ math mode", {
  scope: {},
  mdxOptions: {
    remarkPlugins: [],
    rehypePlugins: []
  },
});

and

const source = await serialize("Hello *world* and $1+1=2$ math mode", {
  scope: {},
  mdxOptions: {
    remarkPlugins: [remarkMath],
    rehypePlugins: [rehypeKatex]
  },
});

give exactly the same source.

console.log(source) output
{
  compiledSource: 'var D=Object.defineProperty,M=Object.defineProperties;var X=Object.getOwnPropertyDescriptors;var p=Object.getOwnPropertySymbols;var m=Object.prototype.hasOwnProperty,r=Object.prototype.propertyIsEnumerable;var u=(o,t,e)=>t in o?D(o,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):o[t]=e,a=(o,t)=>{for(var e in t||(t={}))m.call(t,e)&&u(o,e,t[e]);if(p)for(var e of p(t))r.call(t,e)&&u(o,e,t[e]);return o},s=(o,t)=>M(o,X(t));var y=(o,t)=>{var e={};for(var n in o)m.call(o,n)&&t.indexOf(n)<0&&(e[n]=o[n]);if(o!=null&&p)for(var n of p(o))t.indexOf(n)<0&&r.call(o,n)&&(e[n]=o[n]);return e};const layoutProps={},MDXLayout="wrapper";function MDXContent(e){var n=e,{components:o}=n,t=y(n,["components"]);return mdx(MDXLayout,s(a(a({},layoutProps),t),{components:o,mdxType:"MDXLayout"}),mdx("p",null,"Hello ",mdx("em",{parentName:"p"},"world")," and $1+1=2$ math mode"))}MDXContent.isMDXComponent=!0;\n',
  scope: {}
}

Of course the rendered output doesn’t have any math at all. Everything else works as expected (“world” is in italic for example). So the two plugins aren’t loaded.

I must be missing some very obvious configuration steps here… but what’s wrong?

Version numbers in case they are relevant:

"next": "12.0.7",
"next-mdx-remote": "^3.0.8",
"rehype-katex": "^6.0.2",
"remark-math": "^5.1.1",

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:7 (1 by maintainers)

github_iconTop GitHub Comments

4reactions
BRKalowcommented, Jan 21, 2022

This is likely due to the fact that we’re relying on an older version of remark along with mdx v1, as others have found.

If you would like, give next-mdx-remote@next a try, which uses mdx v2 under the hood and should be compatible with these packages. Otherwise, the alternative is to adjust the versions as @subwaymatch has outlined.

2reactions
subwaymatchcommented, Jan 8, 2022

I also ran into the same issue and took me a while to find out that this was a version issue.

Downgrading remark-math to 3.0.0 or 3.0.1 seems to work. This is also briefly mentioned in https://github.com/hashicorp/next-mdx-remote/issues/148.

There is a Codesandbox example created by @timlrx at https://codesandbox.io/s/katex-forked-jegb7?file=/pages/index.js that renders KaTex correctly. The versions used in the example are:

  • remark: 12.0.1
  • remark-math: 3.0.0
  • rehype-katex: 5.0.0
  • rehype-parse: 9.0.0

I would love to find out if anyone has made KaTeX to work with the latest versions of plugin packages. 🧐

Read more comments on GitHub >

github_iconTop Results From Across the Web

remark/plugins.md at main - GitHub
remark is a popular tool that transforms markdown with plugins. These plugins can inspect and change your markup. You can use remark on...
Read more >
Transforming Markdown with Remark & Rehype - ryanfiller.com
Writing custom plugins to give extra powers to Markdown syntax using the Unified ecosystem.
Read more >
remark-stringify - unified
This is a remark plugin that defines how mdast is turned into markdown. When should I use this? This plugin adds support to...
Read more >
Next.js with MDX tips: Provide shortcuts to article headings
Add rehype-slug to the list of rehype plugins MDX uses. In the case of next.js sites, it is likely wherever you call serialize()...
Read more >
@astrojs/markdown-remark | Yarn - Package Manager
Fix non-hoisted remark/rehype plugin loading. #4842 812658ad2 Thanks @bluwy! - Add missing dependencies, support strict dependency installation (e.g. pnpm) ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found