Create React App + craco + @emotion/babel-preset-css-prop
See original GitHub issueemotion
version: 10.0.5react
version: 16.6.3
Relevant code:
<div css={{color: 'red'}}>hello</div>
What you did:
Use craco with create-react-app. craco is the new version of create-react-app-rewired
# craco.config.js
module.exports = {
babel: {
presets: ['@emotion/babel-preset-css-prop']
}
}
What happened:
It showed in DOM as <div css=[Object]>
Reproduction:
Problem description:
Preset @emotion/babel-preset-css-prop
does not work.
I still need to add /** @jsx jsx/
, import { jsx } from '@emotion/core'
to get it work.
Suggested solution:
Issue Analytics
- State:
- Created 5 years ago
- Comments:6
Top Results From Across the Web
emotion/babel-preset-css-prop
This preset enables the css prop for an entire project via a single entry to the babel configuration. After adding the preset, compiled...
Read more >emotion/babel-plugin examples
Learn how to use @emotion/babel-plugin by viewing and forking example apps that make use of @emotion/babel-plugin on CodeSandbox. ; @react-select/monorepoA ...
Read more >How to setup create-react-app with twin.macro and emotion
Check the twin emotion + react docs for the babel config to use. This is where the documentation leaves room for your own...
Read more >Quick How-to: Use the emotion `css` prop with create-react ...
yarn add @emotion/core react-app-rewired customize-cra --save yarn add @emotion/babel-preset-css-prop --dev. Replace scripts in package.json
Read more >i got a problem when i use MUI with CRA + TS
Uncaught TypeError: Cannot read properties of undefined (reading ... at emotion-element-cbed451f.browser.esm.js:36:1 at renderWithHooks ...
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
TL;DR it works using this craco-config:
Using the preset directly with craco does not work, because craco inserts the presets from
craco.config.js
before the presets from CRA.CRA uses a preset for the babel configuration and the order in which babel presets/plugins executes is:
The plugins of
@emotion/babel-preset-css-prop
must be executed before the plugins of CRA are executed, otherwise the JSX code will have been transformed toReact.createElement
before emotions plugin had a chance to do so.For these reasons it works if we set the plugins directly instead of using the preset. Happy coding 😄
This will not work with ‘Create React App’ as per the documentation: https://emotion.sh/docs/css-prop#babel-preset
You need to use the JSX Pragma instead: https://emotion.sh/docs/css-prop#jsx-pragma