Open olayway opened 2 years ago
@olayway just ran into this bug myself in building on life itself site. IMO this is a bug upstream in contentlayer - shouldn't it be ok with empty pages?
Bumping priority to medium as i suspect others will encounter this error and quite mysterious.
@olayway can we open an issue for this upstream in contentlayer and then move this to blocked.
I just started to build a new handbook using flowershow and ran into this bug. I did not anticipate that this could be caused by an empty page. I was using Umlauts (ä, ü, ö [german]), special charaters (?
) and tried every combination to debug it.
I was deeply expecting that an empty page is not the problem. I would argue, this is a bug and should be fixed. It would have saved my quite some time.
@obstschale thank you for your comment and for reminding us about this issue! I've just committed a quick fix for it, so you and other users shouldn't encounter this bug anymore. Now the page will render correctly, just with no content 😀
@olayway You surprise me again. Thank you in the name of future users who would have stumbled upon this bug. 🙇
Issue in Contentlayer repo: https://github.com/contentlayerdev/contentlayer/issues/370
Not sure if we should fix this or add a note somewhere in the docs, that there shouldn't be any empty pages in the
content
dir.What happens?
Adding an empty page to the
content
dir (content/docs/roadmap.md
in this case) results in a build error:Notes
This is because json file generated by Contentlayer for this page, has
code
value equal to an empty string.Notes
The error is thrown in
useMDXComponent
hook imported fromcontentlayer/hooks
. Sincecode
in case of empty md files will be an empty string, the function created withnew Function(...Object.keys, code)
will have no body, so it will implicitly returnundefined
.https://github.com/contentlayerdev/contentlayer/blob/9c19fbd349eb3c677753ac4c5b6323115e22d31c/packages/next-contentlayer/src/hooks/useMDXComponent.ts#L22-L30
Current workaround