I recently transitioned from Markdown files to MDX using this guide.
While everything seemed to be running smoothly in dev, on build I received the error:
Building static HTML failed for path "/blog/fixing-FOUC/"
See our docs page for more info on this error: https://gatsby.dev/debug-html
WebpackError: TypeError: Cannot read property 'mdx' of undefined
If you’re experiencing this error, you may very well have done what I did, and included your blog folder inside of your pages
directory.
In this case, the GQL query for your individual post will fail because the post page is created twice on build — once manually by you, and then again automatically by the mdx plugin.
The mdx plugin will see the .mdx file in the pages folder, and create a page without a query slug. It is this that causes the query to fail and the error to display.