Using styled-components in a monorepo
See original GitHub issueVersion
> 2.0
Reproduction
We have a UI library built with styled-components that is for use by our team internally as well as with external developers. While this library depends on styled-components, it does not bundle styled components as part of the npm distribution.
Steps to reproduce
Install an npm library that exports components built with styled-components in a React project that also uses styled-component (Create React App in our case)
Expected Behavior
styled-components
should work for both the “local” React app and the imported library components.
Actual Behavior
As soon as the library components are imported to the local React app, the local apps styled-components stop working.
I’m guessing this is related to #1032. The temporary fix we’ve found is to downgrade to 1.4.
Issue Analytics
- State:
- Created 6 years ago
- Reactions:22
- Comments:43 (16 by maintainers)
Top Results From Across the Web
FAQs
You have a monorepo structure for your project (e.g, lerna, yarn workspaces) and styled-components module is a dependency in more than one package...
Read more >Creating a Monorepo with Lerna & Yarn Workspaces
We'll be using React and styled-components to develop our UI components, so let's install those first. $ yarn add --dev -W react react-dom ......
Read more >Share typescript module with every package in a monorepo
I have a monorepo of react components that are built using styled-components, getting their themes from a theme provider.
Read more >Support Multiple Frameworks in a Monorepo
We're trying to build a single button component that uses just one ... and import the CSS Modules styles into our React component...
Read more >Amsterdam Styled Components (ASC)
We aim the components to be aligned with the Amsterdam Design System. ... A monorepo: one source for styled components and everything that...
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
For anyone else landing running into this and landing here, this part of the Styled Components FAQ solved it for me: https://www.styled-components.com/docs/faqs#duplicated-module-in-node_modules
Specifically:
styled-components
as apeerDependency
in my react librarynode_modules
folderI’m using create-react-app and react-app-rewired, so my
config-overrides.js
file in my react app now looks like this:Hope that helps someone else.
@christiannaths I dunno if I’d see this as a CRA issue… most build tools are trending in the direction of zero config. It seems to me that it would be best if
styled-components
didn’t require manually configuring Webpack to behave as expected in a library scenario. I don’t fully understand the underlying issue here butstyled-components
pre 2.0 worked just fine without any special configuration as do other CSS and JS libraries like glamorous etc. It’s a bummerstyled-components
doesn’t.