timlrx / rehype-citation

Rehype plugin to add citation and bibliography from bibtex files
https://rehype-citation.netlify.app
MIT License
41 stars 9 forks source link

Cannot read properties of undefined (reading 'name') #37

Closed qzed closed 3 months ago

qzed commented 5 months ago

After updating from next v14.1.4 to next v14.2.4, rehype-citation with the latest next-mdx-remote-client (v1.0.3) fails with

[Error: [next-mdx-remote-client] error compiling MDX:
Cannot read properties of undefined (reading 'name')

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

when I run yarn build to build/export a static next.js site. I have also tried next-mdx-remote (v5.0.0).

Unfortunately, this error message is not very helpful to me, so I haven't been able to figure out what exactly is going wrong. All I was able to figure out is that if I comment out the rehype-citation plugin, things work as expected. Interestingly, things also work when I run yarn dev.

Please let me know if I can provide any further information to help debug this.

qzed commented 5 months ago

I've narrowed it down a bit more: The error happens when updating from v14.1.4 to v14.2.0. Which unfortunately seems like a rather large update...

timlrx commented 5 months ago

Could you share the repository? Happy to take a closer look to find out what is wrong.

It is unlikely to be just Next.js alone as my template repository uses Next 14.2.3 without issue

qzed commented 5 months ago

I've made the repo public at https://github.com/qzed/qzed.github.io. MDX/rehype related stuff is in https://github.com/qzed/qzed.github.io/blob/main/src/components/Mdx.tsx.

Thanks for looking into this.

timlrx commented 5 months ago

Hi @qzed, I found that it seems to work fine if there's the visibility: devel key in the post. Hence this test post works fine but this one throws an error.

I am still not too sure what's the root cause of the error but my guess is that it might be related to how next-mdx-remote-client is transforming and passing the compiled markdown to Next.js. Maybe there's a change between the Next versions that breaks an expected behaviour...

qzed commented 5 months ago

Hmm, so that key is just something that I use to filter posts based on production/dev env in https://github.com/qzed/qzed.github.io/blob/main/src/lib/blog.tsx#L77.

For me, things work when I run yarn dev but not yarn build. In particular, I can visit both posts successfully when running yarn dev, but yarn build results in an error. By default, that error is only visible in the irl-maxent post, but if I either remove the visibility: devel or modify the filter conditions linked above to make the post appear in the production env as well, it will also break on that.

I think you're correct that it is something with next-mdx-remote-client (or next-mdx-remote, which shows the same issue). I saw that in your template you use contentlayer, so I think I will give that a try as well (I already thought about giving it a try a while ago, so I guess that's a good reason to do so now...).

Anyway, thanks for your help!