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.

gatsby-plugin-mdx: jsxFrag should be set with latest version of @babel-plugin-transform-react-jsx

See original GitHub issue

Description

I’m getting the following error when compiling mdx files that contain a React fragment, <></> on a Gatsby site.

transform-react-jsx: pragma has been set but pragmaFrag has not been set

The issue is because MDX specifies /* @jsx mdx */ as the pragma, but never specifies a pragmaFrag which is now a requirement with babel-plugin-transform-react-jsx@7.9.x`

See the note here: https://babeljs.io/docs/en/next/babel-plugin-transform-react-jsx.html#customizing-with-the-classic-runtime

Steps to reproduce

Unfortunately the code is private so I can’t provide it as an example, but let me know if you want me to recreate in a public repo.

Expected behaviour

gatsby-plugin-mdx should set a jsxFrag value when specifying a custom jsx pragma.

So for example, every time /* @jsx mdx */ is set /* @jsxFrag ... */ should also be set.

Alternatively, babel-plugin-transform-react-jsx should use the default React.Fragment if none is specified.

I’m going to open an issue to babel-plugin-transform-react-jsx for default behavior and to mdx-js to add the same as well.

Related issues:

Let me know if there’s a fragment pragma that makes sense and I’d be happy to do a PR.

Actual behaviour

babel-plugin-transform-react-jsx throws an error.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:7

github_iconTop GitHub Comments

1reaction
existentialismcommented, Mar 24, 2020

We released a fix in 7.9.4 🎉!

1reaction
nicolo-ribaudocommented, Mar 23, 2020

Note: we are restoring the old behavior of not throwing when using the preset, but I recommend enabling the fragment option since we’ll re-introduce the error in Babel 8.

Read more comments on GitHub >

github_iconTop Results From Across the Web

gatsby-plugin-mdx
gatsby-plugin-mdx requires gatsby-source-filesystem to be present and configured to process local MDX files in order to generate the resulting Gatsby nodes ...
Read more >
Images getting wrapped in extra div when using combination ...
Since the update I'm finding that an extra div is wrapping the image which appears to be coming from gatsby-remark-images (although looking at ......
Read more >
Gatsby Changelog | 5.3.0
This means that you can now use ESM-only packages without any workarounds. Here's an example gatsby-config.mjs file: // The latest version of "slugify"...
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