@emotion/babel plugin not working with `experimentalStyled as styled`
See original GitHub issue- The issue is present in the latest release.
- I have searched the issues of this repository and believe that this is not a duplicate.
Current Behavior 😯
The emotion babel plugin does not seem to be working i.e. labels are not applied to classNames.
Expected Behavior 🤔
Labels should be applied to classNames as it is with @emotion/styled
Steps to Reproduce 🕹
- clone this repo
yarn install
in root- go into
/examples/create-react-app-with-typescript
yarn install
yarn eject
yarn add -D @emotion/babel-plugin
- open
./config/webpack.config.js
- go into line
391
and add'@emotion',
there as babel plugin for thetest: /\.(js|mjs|jsx|ts|tsx)$/,
(= babel-loader) - open
src/App.tsx
and add
import { experimentalStyled as styled } from '@material-ui/core';
const Frame = styled('div')`
background-color: green;
`
- modify default export
App
by wrapping the<Container>...</Container>
inside a<Frame>...</Frame>
yarn start
- open browser and check class name for the App’s div, should be something like
css-xyz123
–> There is no labels appended to css class names for better developer experience.
Now replace
import { experimentalStyled as styled } from '@material-ui/core';
with
import styled from '@emotion/styled'
And check class names again! There is now the -Frame
appended to the class name.
Question: Will this experimentalStyled
ever be replaced with proper @emotion/styled
. And is it safe to use already now if I don’t plan on using styled-components
?
Context 🔦
Improve Developer Experience
Your Environment 🌎
`npx @material-ui/envinfo`
System:
OS: macOS 11.3.1
Binaries:
Node: 14.15.1 - ~/.nvm/versions/node/v14.15.1/bin/node
Yarn: 1.22.10 - ~/.yarn/bin/yarn
npm: 7.7.0 - ~/.nvm/versions/node/v14.15.1/bin/npm
Browsers:
Chrome: 90.0.4430.212
Edge: 90.0.818.62
Firefox: Not Found
Safari: 14.1
npmPackages:
@emotion/react: latest => 11.4.0
@emotion/styled: latest => 11.3.0
@material-ui/core: next => 5.0.0-alpha.34
@material-ui/private-theming: 5.0.0-alpha.33
@material-ui/styled-engine: 5.0.0-alpha.34
@material-ui/styles: 5.0.0-alpha.33
@material-ui/system: 5.0.0-alpha.34
@material-ui/types: 6.0.0
@material-ui/unstyled: 5.0.0-alpha.34
@material-ui/utils: 5.0.0-alpha.33
@types/react: latest => 17.0.6
react: latest => 17.0.2
react-dom: latest => 17.0.2
typescript: latest => 4.2.4
Issue Analytics
- State:
- Created 2 years ago
- Reactions:4
- Comments:6 (4 by maintainers)
Top Results From Across the Web
emotion/babel plugin not working with `experimentalStyled as ...
We are currently working on adding documentation for the experimentalStyled() (will be soon exported as a styled() from @material-ui/core/styles ...
Read more >styled() - MUI System
The utility can be used as a replacement for emotion's or styled-components' styled() utility. It aims to solve the same problem, but also...
Read more >Module not found: Error: Can't resolve '@emotion/styled/base ...
I had a similar problem with the recent version of styled components with React. I resolved it by installing the babel plugin styled...
Read more >emotion/babel-plugin
Babel plugin for the minification and optimization of emotion styles. @emotion/babel-plugin is highly recommended, but not required in version 8 and above ...
Read more >Migrate from Emotion - xstyled
You may want to use Emotion Babel plugin for minification of styles, ... Note: importMap has some known issues coming from Emotion side....
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
Working for MUI v5 client-side application Full example: https://codesandbox.io/s/cra-craco-mui-styled-8ji8i
Tip: I could make the
styled
work with :(I used the latest beta version of @material-ui/core, note that
experimentalStyled
was renamed tostyled
)Protip, no need to eject, you can use
customize-cra
for adding the plugin.