Warning about several instances of `styled-components` with Webpack 4 optimization.splitChunks
See original GitHub issueEnvironment
System:
- OS: macOS High Sierra 10.13.6
- CPU: x64 Intel® Core™ i7-4870HQ CPU @ 2.50GHz
- Memory: 162.12 MB / 16.00 GB
- Shell: 3.2.57 - /bin/bash
Binaries:
- Node: 8.6.0 - ~/.nvm/versions/node/v8.6.0/bin/node
- Yarn: 1.2.1 - /usr/local/bin/yarn
- npm: 6.4.1 - ~/.nvm/versions/node/v8.6.0/bin/npm
npmPackages:
- styled-components: ^4.0.2 => 4.0.2
Reproduction
Steps to reproduce
- Create a package with Webpack 4 and two entry points that import
styled-components
. - Add
optimization.splitChunks
towebpack.config.js
and create an explicitvendors.bundle.js
fornode_modules
. - Create bundles and verify that only a single instance of
styled-components
exist invendors.bundle.js
. - Create a HTML page that includes once
vendors.bundle.js
.
Expected Behavior
The console shouldn’t display any warning about multiple instances of styled-components
being initialized.
Actual Behavior
The console displays the message It looks like there are several instances of 'styled-components' initialized in this application...
.
Issue Analytics
- State:
- Created 5 years ago
- Reactions:1
- Comments:12 (1 by maintainers)
Top Results From Across the Web
several instance of styled-component in node modules
2 and my sharable ui library using styled-components "styled-components": "^4.1.1". I have had a entries in peerDependencies as well as in ...
Read more >Ivan Akulov on Twitter: "23) If you use webpack with ...
I've got to admit, I've been doubtful about this optimization for a while – mostly due to compatibility concerns. Like, what if I...
Read more >Webpack 4: Mode and Optimization - Medium
So it's only enabled in production mode. algorithmic cost. warning about bundle size. optimization.removeAvailableModules. Always enabled.
Read more >webpack/webpack - Gitter
What would be the equivalent config for optimization. ... the package to my main react app. styled-components is not found in my package...
Read more >Creating a React App from scratch - Webpack5, TypeScript4+ ...
It becomes difficult to have multiple build outputs for multiple environments. For example, you can add env files that allow you to access ......
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
@probablyup I’ve been investigating a bit, since it was clear from my bundles that
styled-components
(and React, for that matter) was included in a single bundle but evaluated twice. It turns out that this is a change in behaviour from Webpack 3. It would be a good idea to add a Webpack 4 configuration snippet to the FAQ related section. If this is hosted somewhere I can submit a PR.You need to make sure it’s only in a single bundle. If you’re getting that warning it’s not being deduped properly. styled-components is a singleton library like react and loading multiple copies of it will cause all sorts of problems.