Styled Components not working
See original GitHub issueI was trying to adopt WMR in a personal project but kept running into issues. I’ve found that it has something to do with styled-components
, but I’m not sure what’s happening.
Error (in browser)
Uncaught SyntaxError: The requested module '/@npm/react-is' does not provide an export named 'typeOf'
Steps to Reproduce
- Run
npm init wmr
- Run
npm i styled-components
- Import styled-components into the
index.js
file,import styled from 'styled-components';
- Run
npm start
, notice the page does not render and the error in the console
Issue Analytics
- State:
- Created 3 years ago
- Reactions:2
- Comments:14 (5 by maintainers)
Top Results From Across the Web
Extending styles with styled-components not working
I'm trying to extend styles for a react component using styled-components but is not working. AFAIK, I'm doing it the right way, ...
Read more >Why Is styled-components "styled" Wrapper Not Working With ...
To avoid this issue, make sure the React component you're using with the styled() wrapper attaches the passed-in className prop (or style prop, ......
Read more >Issues · styled-components/styled-components - GitHub
customSyntax for Stylelint v14+ · Can't use <use> element with styled-components · Upgrading react dependency to 18.1 · css animation doesn't work if...
Read more >How To Use Styled-Components In React - Smashing Magazine
Styled components are independent of each other, and you do not have to ... Let's say you're working on a landing page, and...
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 Free
Top 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
Alright, I finally chased this one down. It’s a bug in styled-components, which uses a fairly old version of Rollup’s commonjs plugin to generate its ESM bundles that is just producing a nonsensical import:
They’d originally told folks to fix this in their own configurations, but having this be broken by default doesn’t seem adequate. Instead, I’ve submitted a PR that implements the correct import generation in their build setup:
https://github.com/styled-components/styled-components/pull/3367
One thing I did find while digging is that this import was broken in 5.1.0 -
styled-components@5.0.1
should work.@damianobarbati The
has fix
tag is incorrect, I think we forgot to remove it.I’ve been working on revamping the npm plugin and on the commonjs handling over the past days and got it to render. There is a bit of remaining work to be done before this can be PR’ed, but it’s progressing well so far.