Unable to reference frontmatter fields inside MDX
See original GitHub issueDescription
Documentation states https://www.gatsbyjs.org/docs/mdx/writing-pages/ that Frontmatter is also available in props.pageContext.frontmatter and can be accessed in blocks of JSX in your MDX document:
When I try to read my frontmatter inside mdx I get an error: Cannot read property 'frontmatter' of undefined
System: OS: macOS 10.15.2 CPU: (16) x64 Intel® Core™ i9-9980HK CPU @ 2.40GHz Shell: 5.7.1 - /bin/zsh Binaries: Node: 12.14.1 - /usr/local/bin/node npm: 6.13.4 - /usr/local/bin/npm Languages: Python: 2.7.16 - /usr/bin/python npmPackages: gatsby: ^2.15.15 => 2.15.15 gatsby-image: ^2.2.19 => 2.2.19 gatsby-plugin-alias-imports: ^1.0.5 => 1.0.5 gatsby-plugin-catch-links: ^2.1.9 => 2.1.9 gatsby-plugin-facebook-pixel: ^1.0.3 => 1.0.3 gatsby-plugin-google-analytics: ^2.1.16 => 2.1.16 gatsby-plugin-google-gtag: ^1.1.8 => 1.1.8 gatsby-plugin-mdx: ^1.0.41 => 1.0.41 gatsby-plugin-react-helmet: ^3.1.7 => 3.1.7 gatsby-plugin-sharp: ^2.2.22 => 2.2.22 gatsby-plugin-sitemap: ^2.2.12 => 2.2.12 gatsby-plugin-styled-components: ^3.1.5 => 3.1.5 gatsby-remark-autolink-headers: ^2.1.10 => 2.1.10 gatsby-remark-copy-linked-files: ^2.1.19 => 2.1.19 gatsby-remark-images: ^3.1.22 => 3.1.22 gatsby-source-filesystem: ^2.1.22 => 2.1.22 gatsby-transformer-json: ^2.2.25 => 2.2.25 gatsby-transformer-remark: ^2.6.22 => 2.6.22 gatsby-transformer-sharp: ^2.2.14 => 2.2.14 npmGlobalPackages: gatsby-cli: 2.8.29
Issue Analytics
- State:
- Created 4 years ago
- Comments:6 (1 by maintainers)
Top GitHub Comments
Maybe docs need to be updated? I am using
MDXRenderer
and nothing was accessible until I have manually passed a parameterI’ve run into the same problem - on top of that, passing
frontmatter
as a prop toMDXRenderer
breaks the build when trying to use it, even thoughgatsby develop
works just fine. Here’s my usage:In my post component:
<MDXRenderer frontmatter={post.frontmatter}>{post.body}</MDXRenderer>
In my
index.mdx
file:Running
gatsby develop
displays the frontmatter output as expected. Runninggatsby build
throws an error: