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.

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

See original GitHub issue

Subject of the issue

I’m getting the following error when compiling mdx files that use 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

Your environment

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

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.

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:13 (5 by maintainers)

github_iconTop GitHub Comments

3reactions
existentialismcommented, Mar 24, 2020

We released a fix in 7.9.4 🎉!

2reactions
nicolo-ribaudocommented, Mar 25, 2020

Yes, explicitly setting the options should make it work both with Babel 7 and 8!

Read more comments on GitHub >

github_iconTop Results From Across the Web

babel/plugin-transform-react-jsx
Automatic runtime is a feature added in v7.9.0 . With this runtime enabled, the functions that JSX compiles to will be imported automatically....
Read more >
@babel/plugin-transform-react-jsx | Yarn - Package Manager
Intro. Babel is a tool that helps you write code in the latest version of JavaScript. When your supported environments don't support certain...
Read more >
Introducing the New JSX Transform – React Blog
First, you'll need to update to the latest Babel and plugin transform. If you are using @babel/plugin-transform-react-jsx : # for npm users npm ......
Read more >
Callbag JSX | How to Install
callbag-jsx itself is a small package that can be installed via NPM (or yarn). ... repo on GitHub, you can conveniently start a...
Read more >
Getting Started | Preact: Fast 3kb React alternative with the ...
You don't have to use ES2015 to use Preact... but you should. This guide assumes you have some sort of ES2015 build set...
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