ChristopherBiscardi / gatsby-mdx

Gatsby+MDX • Transformers, CMS UI Extensions, and Ecosystem Components for ambitious projects
https://gatsby-mdx.netlify.com/
715 stars 100 forks source link

[bug] path url is null when creating page from mdx file #410

Closed adekunleoduye closed 5 years ago

adekunleoduye commented 5 years ago

Describe the bug When dynamically creating pages from mdx files, the node.frontmatter.path is return as null.

To Reproduce Repo: https://github.com/adekunleoduye/gatsby-issue When running gatsby develop I get the error below.

> gatsby develop

success open and validate gatsby-configs -
success load plugins - 0.421 s
success onPreInit - 0.005 s
info One or more of your plugins have changed
since the last time you ran Gatsby. As
a precaution, we're deleting your site's cache
success initialize cache - 0.018 s
success copy gatsby files - 0.023 s
success onPreBootstrap - 0.008 s
success source and transform nodes - 0.585 s
success building schema - 0.171 s
Your site's "gatsby-node.js" must set the page
⠀
{ path: null,
  component:
   '/Users/adekunleoduye/Projects/wink-documen
tation/src/templates/componentTemplate.js',
error See the documentation for createPage htt
⠋ createPages
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! wink-documentation@0.1.0 dev: `gatsby develop`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the wink-documentation@0.1.0 dev script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     /Users/adekunleoduye/.npm/_logs/2019-06-28T12_34_45_722Z-debug.log
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! wink-documentation@0.1.0 start: `npm run dev`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the wink-documentation@0.1.0 start script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     /Users/adekunleoduye/.npm/_logs/2019-06-28T12_34_45_758Z-debug.log

What happened.

Environment

System:
    OS: macOS 10.14.5
    CPU: (12) x64 Intel(R) Core(TM) i7-8750H CPU @ 2.20GHz
    Shell: 3.2.57 - /bin/bash
  Binaries:
    Node: 10.16.0 - /usr/local/bin/node
    Yarn: 1.15.2 - /usr/local/bin/yarn
    npm: 6.9.0 - /usr/local/bin/npm
  Languages:
    Python: 2.7.10 - /usr/bin/python
  npmPackages:
    gatsby: ^2.10.0 => 2.11.0
    gatsby-image: ^2.1.2 => 2.2.3
    gatsby-mdx: ^0.6.3 => 0.6.3
    gatsby-plugin-less: ^2.0.13 => 2.1.0
    gatsby-plugin-manifest: ^2.1.1 => 2.2.0
    gatsby-plugin-offline: ^2.1.1 => 2.2.0
    gatsby-plugin-react-helmet: ^3.0.12 => 3.1.0
    gatsby-plugin-sharp: ^2.1.3 => 2.2.1
    gatsby-source-filesystem: ^2.0.38 => 2.1.1
    gatsby-transformer-react-docgen: ^4.0.2 => 4.1.0
    gatsby-transformer-remark: ^2.3.12 => 2.5.0
    gatsby-transformer-sharp: ^2.1.21 => 2.2.0
  npmGlobalPackages:
    gatsby-cli: 2.6.4

Expected behavior

> gatsby develop

success open and validate gatsby-configs -
success load plugins - 0.405 s
success onPreInit - 0.004 s
success initialize cache - 0.006 s
success copy gatsby files - 0.032 s
success onPreBootstrap - 0.007 s
success source and transform nodes - 0.592 s
success building schema - 0.176 s
success createPages - 0.032 s
success createPagesStatefully - 0.028 s
success onPreExtractQueries - 0.003 s
success update schema - 0.020 s
success extract queries from components -
success write out requires - 0.009 s
success write out redirect data - 0.004 s
success Build manifest and related icons -
success onPostBootstrap - 0.116 s
⠀
info bootstrap finished - 3.176 s
⠀
success run static queries - 0.043 s — 4/4
success run page queries - 0.150 s — 12/12
 DONE  Compiled successfully in 2391ms
⠀
You can now view wink-documentation in the
⠀
  http://localhost:8000/
⠀
View GraphiQL, an in-browser IDE, to explore
⠀
  http://localhost:8000/___graphql
⠀
Note that the development build is not
To create a production build, use npm run 
⠀
ℹ 「wdm」:
ℹ 「wdm」: Compiled successfully.
 WAIT  Compiling...                 8:34:18 AM
⠀
ℹ 「wdm」: Compiling...
 DONE  Compiled successfully in 35ms

Screenshots If applicable, add screenshots to help explain your problem.

Also, when exploring the query from allMdx, for some reason there are 8 results (supposed to be 1) Screen Shot 2019-07-01 at 5 17 20 PM

ChristopherBiscardi commented 5 years ago

It looks like you're using the react-docgen plugin too? Because of this, you actually have more MDX content than just the files that are on disk. react-docgen creates a set of markdown-content nodes and gatsby-mdx will process any node with the mediaType: text/markdown.

You can structure your query from allFile instead if you want to filter by the sourceInstanceName of your gatsby-source-filesystem, and use childMdx on the File node to get to the MDX content instead. This will restrict the query to only return values from the filesystem source.

adekunleoduye commented 5 years ago

@ChristopherBiscardi sounds good...thanks!