Issues using emotion/styled with ES Modules
See original GitHub issueCurrent behavior:
When using import styled from "@emotion/styled"
, in a package setup to use esm, styled has a single key default
To reproduce:
- Clone https://github.com/maddijoyce/emotion-esm-issue
- Run npm test
Expected behavior:
As in the above example, using import styled from "@emotion/styled"
, styled should have styled.h1, styled.h2, etc
Environment information:
- node version: 16.13.2
- @emotion/styled version: 11.8.1
Some additional background:
Issue first discovered here - https://github.com/facebook/jest/issues/12571
Issue Analytics
- State:
- Created a year ago
- Reactions:5
- Comments:12 (3 by maintainers)
Top Results From Across the Web
Styled-components vs. Emotion for handling CSS
styled -components and Emotion are two main CSS-in-JS libraries that developers mostly use while styling components in popular JavaScript ...
Read more >Module not found: Error: Can't resolve '@emotion/styled/base ...
This is an issue caused by the break name change of emotion 11. So far storybook internally is still looking for the v10...
Read more >@emotion/styled - npm
Start using @emotion/styled in your project by running `npm i ... There are 6735 other projects in the npm registry using @emotion/styled.
Read more >Install - Emotion
There are lots of ways to use Emotion, if you're using React, the easiest way to get started is to use the @emotion/react...
Read more >the `@emotion/core` package has been renamed to ... - You.com
You don't need @emotion/react in v10. You don't need @emotion/styled unless you want to use Styled Components (e.g. ...
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
@Andarist This issue is not resolved after #2819 (
@emotion/styled@11.10.0
) and it should not be closed.By adding some
console.log
undernode_modules/@emotion/styled/dist/emotion-styled.esm.js
andnode_modules/@emotion/styled/dist/emotion-styled.cjs.js
, you can see clearly that Node.js is still importing the CJS version of emotion. CommonJS doesn’t include real default export, that’s why we are seeing this error.As someone already mentioned, we need to use
.mjs
for esm build.For those who came here trying to make work emotion-js + vite (which using ESM by default) here is solution:
The
cjsInterop
plugin is a crucial part, this plugin actually do what @vtereshyn wrote in the comment above