question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Warning about several instances of `styled-components` with Webpack 4 optimization.splitChunks

See original GitHub issue

Environment

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

  1. Create a package with Webpack 4 and two entry points that import styled-components.
  2. Add optimization.splitChunks to webpack.config.js and create an explicit vendors.bundle.js for node_modules.
  3. Create bundles and verify that only a single instance of styled-components exist in vendors.bundle.js.
  4. 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:closed
  • Created 5 years ago
  • Reactions:1
  • Comments:12 (1 by maintainers)

github_iconTop GitHub Comments

3reactions
alfonsomunozpomercommented, Oct 30, 2018

@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.

1reaction
probablyupcommented, Oct 29, 2018

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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found