JavaScript for WordPress › Forums › Gatsby › Gatsby Basics: gatsby-mdx is depreciated, use gatsby-plugin-mdx instead
- This topic has 4 replies, 5 voices, and was last updated 4 years, 10 months ago by Jory Goehle.
-
AuthorPosts
-
September 9, 2019 at 5:06 pm #117588StuartParticipant
Hi Zac,
Unfortunately your video on the Gatsby Basics course Creating Content with Markdown (MDX) is now out of date because gatsby-mdx is depreciated.
I managed to switch to using gatsby-plugin-mdx and it works fine, also the video is a lot longer than 5:03 🙂
This error also effects the next video Creating Dynamic Page Templates. There is no longer a code object in mdx, only body and when I try to code along as per the instructions I get an error:
ERROR #85907 GRAPHQL
There was an error in your GraphQL query:
– Unknown field ‘code’ on type ‘Mdx’.
To fix this you have to do:
query MyQuery($slug: String!) {
mdx(frontmatter: { slug: { eq: $slug } }) {
frontmatter {
title
}
body
}
}and
export default ({
data: {
mdx: {
frontmatter: { title },
body: content,
},
},
}) => (
<Layout>
<h1>{title}</h1>
<MDXRenderer>{content}</MDXRenderer>
</Layout>
)Now I get the post body showing 🙂
- This topic was modified 5 years, 1 month ago by Zac Gordon.
September 9, 2019 at 5:19 pm #117589Zac GordonKeymasterThanks for the ping! Actually update this in a later video, but will link to this from the video!
October 24, 2019 at 8:00 pm #121461Alex FornutoParticipantRelated, when I got to Adding React Components to MDC Files, I was unable to load the Shoutout component from within the markdown file. To resolve:
- Go to
posts.js
and add:import { MDXProvider } from "@mdx-js/react" import Shoutout from "../components/shoutout" const shortcodes = { Shoutout }
- And where you import the content, adjust to:
<MDXProvider components={shortcodes}> <MDXRenderer>{content}</MDXRenderer> </MDXProvider>
- Now in your markdown file, you can use
<Shoutout>
tags without importing.
I hope this helps others.
- This reply was modified 5 years, 1 month ago by Alex Fornuto. Reason: Adjust formatting
November 27, 2019 at 12:09 am #125503Leland FiegelParticipantJust wanted to add to this post because it is linked to from this lesson: https://javascriptforwp.com/courses/gatsby-basics/sections/creating-content-with-markdown-mdx-503/
I found that I couldn’t see allMdx available in GraphiQL content without some changes.
Instead of npm installing gatsby-mdx, install gatsby-plugin-mdx, as described here: https://www.gatsbyjs.org/docs/mdx/getting-started/#add-mdx-to-an-existing-gatsby-site
If you already followed along with the tutorial:
– In your project directory, remove the ‘gatsby-mdx’ line in your package.json
– Delete package-lock.json
– Run the following terminal command in the project directory: npm install –save gatsby-plugin-mdx @mdx-js/mdx @mdx-js/react
– This will update your package.json and generate a new package-lock.json file
– Reference your newly installed gatsby-plugin-mdx plugin in gatsby-config.js (merely replacing with “gatsby-mdx” with “gatsby-plugin-mdx” seems to do the trick)
– Run: gatsby develop
– At this point, you will see a new “allMdx” section in your GraphiQL which means it can now be queried just like in the course videoHope this helps!
January 21, 2020 at 1:10 pm #133545Jory GoehleParticipantThanks Leland Fiegel!
-
AuthorPosts
- You must be logged in to reply to this topic.