Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gatsby-plugin-mdx: getNodesByType is not passed to remark plugins #24400

Closed
kamranayub opened this issue May 24, 2020 · 1 comment · Fixed by #24516
Closed

gatsby-plugin-mdx: getNodesByType is not passed to remark plugins #24400

kamranayub opened this issue May 24, 2020 · 1 comment · Fixed by #24516
Labels
type: bug An issue or pull request relating to a bug in Gatsby

Comments

@kamranayub
Copy link
Contributor

Description

I am writing my first gatsby-remark plugin and following the documentation it says

The first parameter is all of the default properties that can be used in plugins (actions, store, getNodes, schema, etc.) plus a couple just for gatsby-transformer-remark plugins. The most relevant field for our purposes is the markdownAST field which is destructured in the code snippet above.

Source: https://www.gatsbyjs.org/tutorial/remark-plugin-tutorial/#setting-up-a-plugin

Because of this, I assumed I had access to getNodesByType but it actually throws an error:

getNodesByType is not a function

I think it was due to this recent fix by @johno (but it seems like it would have failed previously if someone tried using getNodes too).

63d091a

Steps to reproduce

Make a plugin and try to destructure getNodesByType

index.js

module.exports = ({ getNodesByType, markdownAST }, pluginOptions) => {
  const customNodes = getNodesByType('CoolNodeType')
                   // ^-- Throws an error

  return markdownAST
}

Expected result

From the docs, I expected to be able to access all shared helpers including getNodesByType. I am trying to get some custom nodes since they contain some data I want to pass to my Remark plugin.

Actual result

Due to the spreading happening here:

The getNodesByType is not passed and so it's missing.

Environment

Run gatsby info --clipboard in your project directory and paste the output here.

  System:
    OS: Windows 10 10.0.18363
    CPU: (8) x64 Intel(R) Core(TM) i7-3770K CPU @ 3.50GHz
  Binaries:
    Node: 12.16.3 - C:\Program Files\nodejs\node.EXE
    Yarn: 1.22.4 - C:\Program Files (x86)\Yarn\bin\yarn.CMD
    npm: 6.14.4 - C:\Program Files\nodejs\npm.CMD
  Languages:
    Python: 2.7.11
  Browsers:
    Edge: 44.18362.449.0
  npmPackages:
    gatsby: 2.22.9 => 2.22.9 
    gatsby-cli: 2.12.16 => 2.12.16 
    gatsby-link: 2.4.2 => 2.4.2 
    gatsby-plugin-catch-links: 2.3.1 => 2.3.1 
    gatsby-plugin-mdx: 1.2.12 => 1.2.12 
    gatsby-plugin-react-helmet: 3.3.1 => 3.3.1 
    gatsby-plugin-sharp: 2.6.2 => 2.6.2 
    gatsby-remark-autolink-headers: 2.3.1 => 2.3.1 
    gatsby-remark-copy-linked-files: 2.3.2 => 2.3.2 
    gatsby-remark-images: 3.3.2 => 3.3.2 
    gatsby-remark-prismjs: 3.5.1 => 3.5.1 
    gatsby-source-filesystem: 2.3.1 => 2.3.1 
    gatsby-source-github: 0.0.2 => 0.0.2 
    gatsby-source-typedoc: 1.0.6 => 1.0.6 
    gatsby-transformer-remark: 2.8.7 => 2.8.7 
    gatsby-transformer-sharp: 2.5.2 => 2.5.2 
  npmGlobalPackages:
    gatsby-source-typedoc: 1.0.6
@kamranayub kamranayub added the type: bug An issue or pull request relating to a bug in Gatsby label May 24, 2020
@gatsbot gatsbot bot added the status: triage needed Issue or pull request that need to be triaged and assigned to a reviewer label May 24, 2020
@kamranayub
Copy link
Contributor Author

If this is not intended, I am happy to submit a PR to fix tomorrow if no one else gets to it. Just let me know!

@LekoArts LekoArts added topic: MDX and removed status: triage needed Issue or pull request that need to be triaged and assigned to a reviewer labels May 25, 2020
kamranayub added a commit to kamranayub/gatsby that referenced this issue May 26, 2020
johno pushed a commit to johno/gatsby that referenced this issue May 28, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: bug An issue or pull request relating to a bug in Gatsby
Projects
None yet
2 participants