@emotion/babel-plugin with React 17 and Typescript 4 and webpack does not apply labels
See original GitHub issueCurrent behavior:
Using the latest version of @emotion/css
, @emotion/babel-plugin
and react
the labels to classnames using the css
function do not apply at all (not even the default ones which should be applied in development).
.babelrc
"plugins": [
"react-hot-loader/babel",
[
"@emotion",
{
"sourceMap": false,
"autoLabel": "always",
"labelFormat": "[filename]__[local]"
}
]
],
To reproduce:
Used a custom sandbox to be able to edit the .babelrc
file to show the plugin not working
https://codesandbox.io/s/peaceful-volhard-vhdkp?file=/src/index.tsx
Check the index.tsx
to see the usage, and the .babelrc
config to see the settings configured as per the documentation.
Any setting in the .babelrc
, or even when using inline options in the webpack config, nothing changes. Labels are always just the hashes, not even the default [local]
is applied.
Expected behavior:
Components with className
set to the @emotion/css
css
value should have labels
Note that it seems to work with Parcel (without TS) https://codesandbox.io/s/react-optional-chaining-demo-forked-ttuv5?file=/package.json
Environment information:
react
version: 17.0.2@emotion/css
version: 11.1.3@emotion/babel-plugin
version: 11.2.0webpack
version: 4.41.2
Issue Analytics
- State:
- Created 2 years ago
- Comments:6 (3 by maintainers)
Top GitHub Comments
Ok found the issue: in the
tsconfig.json
thejsx
field was set toreact
meaning all<div />
would get converted toReact.createElement
and thusemotion
could not find where to attach the label. (see https://github.com/emotion-js/emotion/issues/1748)For anyone bumping into this and having issues with getting the compilation going with
babel-loader
andts-loader
here is what i have in my babel config:The
automatic
is needed otherwise the react babel preset failed to compile (see https://github.com/gatsbyjs/gatsby/issues/27694).✌️
Sorry I don’t know that you care about
build-time type checking
. Yep,awesome-typescript-loader
can work as well. In my solution you just need try to change the loader config order.[ 'babel-loader', 'awesome-typescript-loader' ]
to[ 'awesome-typescript-loader' , 'babel-loader']
, I have no time to digest the deep reason why we need do it, but I assured that emotion’sadd label
action is work atnodejs
side, the babel plugin running order is important. I can’t give u more info about it cause i am not ababel
expert. 😄 @nicmosc