question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

MDX Page not being created through `createPage`

See original GitHub issue

Description

I am trying to programmatically generate pages from mdx files. It worked when I was using md files, but now the createPage seems to be failing and not referencing the template as a page and I am getting this warning and the blog post pages are broken:

warn The GraphQL query in the non-page component "/Users/wking/sites/wking-io/src/templates/article.js" will not be run.
Exported queries are only executed for Page components. It's possible you're
trying to create pages in your gatsby-node.js and that's failing for some
reason.

If the failing component(s) is a regular component and not intended to be a page
component, you generally want to use a <StaticQuery> (https://gatsbyjs.org/docs/static-query)
instead of exporting a page query.

If you're more experienced with GraphQL, you can also export GraphQL
fragments from components and compose the fragments in the Page component
query and pass data down into the child component — http://graphql.org/learn/queries/#fragments

Steps to reproduce

  1. Clone and build repo here: https://github.com/wking-io/wking-io
  2. See warning in output
  3. Visit http://localhost:8000/content/articles/why-use-elm-in-wordpress/ to see page not being passed into template as defined in gatsby-node.js

Expected result

I expect the page to be generated inside of the template as seen here: https://www.wking.io/content/articles/wordpress-needs-a-frontend-framework/

Actual result

I get the warning in the build out put and the mdx file contents are just rendered on the apge as is.

Environment

System: OS: macOS 10.14.5 CPU: (8) x64 Intel® Core™ i7-6820HQ CPU @ 2.70GHz Shell: 5.3 - /bin/zsh Binaries: Node: 10.15.3 - ~/.nvm/versions/node/v10.15.3/bin/node Yarn: 1.15.2 - /usr/local/bin/yarn npm: 6.10.2 - ~/.nvm/versions/node/v10.15.3/bin/npm Languages: Python: 2.7.10 - /usr/bin/python Browsers: Chrome: 75.0.3770.142 Firefox: 68.0.1 Safari: 12.1.1 npmPackages: gatsby: 2.13.31 => 2.13.31 gatsby-image: 2.2.7 => 2.2.7 gatsby-plugin-manifest: ^2.1.1 => 2.1.1 gatsby-plugin-mdx: 1.0.18 => 1.0.18 gatsby-plugin-offline: ^2.1.3 => 2.1.3 gatsby-plugin-postcss: 2.1.0 => 2.1.0 gatsby-plugin-prefetch-google-fonts: 1.4.2 => 1.4.2 gatsby-plugin-react-helmet: ^3.0.12 => 3.0.12 gatsby-plugin-sharp: 2.2.9 => 2.2.9 gatsby-source-filesystem: ^2.0.43 => 2.0.43 gatsby-transformer-json: 2.2.2 => 2.2.2 gatsby-transformer-remark: 2.6.7 => 2.6.7 gatsby-transformer-sharp: 2.2.5 => 2.2.5

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:3
  • Comments:6 (1 by maintainers)

github_iconTop GitHub Comments

31reactions
bayareacodercommented, Sep 7, 2019

I believe the action here should be to document this a lot better in the Gatsby docs since, as the OP mentions, it works for a markdown plugin (i.e. you can have .md files under src/pages and still use createPage) but not for mdx plugin. I just spent hours stuck on this while transferring a site from markdown to mdx until I stumbled on this page. It should be made clear that you need to keep jsx files under src/pages and mdx files under src/content, if you want to use gatsby_node to programmatically create pages from mdx.

7reactions
Vintharascommented, Jan 16, 2020

I’ve been stuck on the same issue for hours 😦

Read more comments on GitHub >

github_iconTop Results From Across the Web

html - Gatsby mdx pages not rendering fully when placed in ...
I am using markdown pages with mdx, and I have all my markdown files under subfolders of the src/pages directory, like this:
Read more >
Adding MDX Pages | Gatsby
When using the createPage action to programatically create pages, you should use the following URI pattern for your page component: your-layout-component.js?__
Read more >
Programmatically Creating Pages | GatsbyJS 中文网
First, create a component that accepts the queried MDX data (which will be added in the next step). Then, write a query that...
Read more >
Fixing the Build: Part 2 - Thinkster.io
The first problem is that our createPages function in gatsby-node.js is bringing in too many files; it's bringing in all of the Markdown...
Read more >
How to create dynamic pages in Gatsby from MDX and YAML?
createPage API. More about MDX. What is MDX? MDXProvider. Other Useful Resources; Wrap Up!! Gatsby allows you to tie data from ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found