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.

React 17 + new JSX transform + JSX pragma/pragmaFrag

See original GitHub issue

Current behavior:

I’m currently using a barebones nextJS deployment with React 17.0.0-rc.3 and have added emotion to the project. I wanted to test out the new JSX transform but I’m running into issues, whenever I set

/** @jsx jsx */
import { jsx, css } from '@emotion/core';

in a component, I run into compilation issues in said file. SyntaxError: pragma and pragmaFrag cannot be set when runtime is automatic.

my .babelrc file but is set below, and the issue is obviously with the value of runtime being set to automatic. that said, that’s how babel 8 will be set moving forward, and also is what allows the removal of requiring React in every file.

    {
      "presets": [
        "next/babel",
        ["@babel/preset-react", {
          "runtime": "automatic"
        }]
      ],
      "plugins": ["emotion"]
    }

I’m not sure if here, react, or the babel issues repo was the best to post in but settled here given it’s an issue with emotion’s setting of the pragma. I suspect a lot of this issue will be popping up soon once react 17 ships, so I thought i’d raise an issue so people aren’t lost on day 1 after ripping out all of the 'import React from “react”` across their app and realizing they just made a huge mistake.

Environment information:

  • react version: 17.0.0-rc.3
  • emotion version: 10.0.35

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:44
  • Comments:26 (8 by maintainers)

github_iconTop GitHub Comments

48reactions
fobbyalcommented, Oct 30, 2020

I’ve gotten the following to work with CRA4. This tells babel to transpile the file using the old way

/** @jsxRuntime classic */
/** @jsx jsx */
import { jsx } from '@emotion/core'
28reactions
Andaristcommented, Oct 14, 2020

@n8sabes just to confirm - you are using a prerelease of CRA 4 and React 17, right? I’m afraid that I don’t have a good recommendation for this situation yet. You could create a module like this: https://github.com/emotion-js/emotion/pull/1970#issuecomment-707173919 and use @jsxImportSource pragma to point to it, but it ain’t a super pleasant experience. We may be forced to recommend that new pragma in combination with CRA once we implement new factories for React 17. It’s a shame as it’s significantly longer than the current one:

/** @jsx jsx */

vs

/** @jsxImportSource @emotion/react */
Read more comments on GitHub >

github_iconTop Results From Across the Web

Introducing the New JSX Transform – React Blog
Although React 17 doesn't contain new features, it will provide support for a new version of the JSX transform.
Read more >
React 17 introduces new JSX transform - Saeloun Blog
A Babel plugin called @babel/plugin-transform-react-jsx transforms JSX into standard JavaScript objects that a JavaScript engine can parse.
Read more >
React 17: New JSX Transform - JavaScript in Plain English
React 17, 16.4, 15.7, and 0.14.10 released a new feature that no longer requires importing React to transform JSX. This is a comprehensive...
Read more >
React 17: New Features!! - JSX Transform is Amazing!!
Become A VS Code SuperHero Today: http://vsCodeHero.comAbout a month ago React 17 was announced and it seemed to be a very underwhelming ...
Read more >
React.js 17: No New Features and New JSX Transform
One of the greatest internal improvements React 17 has is the new JSX transform. Prior to React 17, when you write JSX code,...
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 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