Setting up a basic React/Emotion project results in Exception: pragma and pragmaFrag cannot be set
See original GitHub issueCurrent 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:
- Setup a project:
$ npx create-react-app react-emotion-baseline
$ cd react-emotion-baseline
$ yarn add @emotion/react
- Then, add the following to the top of
src/App.js
(as per introduction docs:
/** @jsx jsx */
import { css, jsx } from '@emotion/react'
- Run:
$ yarn start
Expected behavior:
It should compile.
Environment information:
react
version:^17.0.2
@emotion/react
version:^11.4.0
Issue Analytics
- State:
- Created 2 years ago
- Comments:7 (3 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
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/12542Unfortunately, those PRs/issues got stale and there is nothing happening in those directions.
Create React App 4 then
/** @jsx jsx */
pragma might not work and you should use/** @jsxImportSource @emotion/react */
instead.