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.

Setting up a basic React/Emotion project results in Exception: pragma and pragmaFrag cannot be set

See original GitHub issue

Current behavior:

First time attempting to use Emotion with React, first created an app using Create React App, then added @emotion/react as a dependency. Finally, followed docs to include:

/** @jsx jsx */
import { jsx } from '@emotion/react'

Result is an exception at compile time:

./src/App.js
SyntaxError: <project_root>/src/App.js: pragma and pragmaFrag cannot be set when runtime is automatic.

Sample repo can be found here: https://github.com/feefhq/react-emotion-baseline

To reproduce:

  1. Setup a project:
$ npx create-react-app react-emotion-baseline
$ cd react-emotion-baseline
$ yarn add @emotion/react
  1. Then, add the following to the top of src/App.js (as per introduction docs:
/** @jsx jsx */
import { css, jsx } from '@emotion/react'
  1. Run:
$ yarn start

Expected behavior:

It should compile.

Environment information:

  • react version: ^17.0.2
  • @emotion/react version: ^11.4.0

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:7 (3 by maintainers)

github_iconTop GitHub Comments

3reactions
Andaristcommented, Oct 14, 2021

If you are using Emotion 11 then yes - IIRC /** @jsxImportSource @emotion/react */ is the correct way to use this. An improvement to our ESLint plugin has just been merged: https://github.com/emotion-js/emotion/pull/2353 so you could soon use it to automate this in your codebase. Note that I’ve been trying to improve this and related issues: https://github.com/facebook/create-react-app/issues/9847 https://github.com/babel/babel/pull/12542

Unfortunately, those PRs/issues got stale and there is nothing happening in those directions.

3reactions
agiledotscommented, Aug 25, 2021

Create React App 4 then /** @jsx jsx */ pragma might not work and you should use /** @jsxImportSource @emotion/react */ instead.

/** @jsxImportSource @emotion/react */
import { jsx, css } from "@emotion/react";
Read more comments on GitHub >

github_iconTop Results From Across the Web

Migrating React 17 & Emotion 11: "pragma and pragmaFrag ...
Migrating React 17 & Emotion 11: "pragma and pragmaFrag cannot be set when runtime is automatic." #react #emotion. Hi there!
Read more >
Bountysource
Setting up a basic React/Emotion project results in Exception: pragma and pragmaFrag cannot be set.
Read more >
SyntaxError: pragma and pragmaFrag cannot be set when ...
I'm migrating a project from Next 9 to Next 11 which uses webpack5 by default. After fixing the loader issue as shown in...
Read more >
React 17 Emotion Build Error - Jiahao Chen
If you use Emotion in React 17, you might find the following problem: pragma and pragmaFrag cannot be set when runtime is automatic....
Read more >
unknown compiler option jsximportsource
... Setting up a basic React/Emotion project results in Exception: pragma and pragmaFrag cannot be set, Remove extra @jsxImportSource annotation from file ......
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