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.

Duplicate modules - NOT solvable by `npm dedupe`

See original GitHub issue

Do you want to request a feature or report a bug? Bug

What is the current behavior? Two identical sub-dependencies are being included twice in the build.

If the current behavior is a bug, please provide the steps to reproduce. projectA depends on libA@^2.0.0, depA and depB. depA and depB both depend on libA@^1.0.0

This results in a directory structure like this:

projectA
- node_modules
-- libA
-- depA
---- node_modules/libA
-- depB
---- node_modules/libA 

When the project is built, included in the bundle are:

libA@2.0.0
depA
depB
libA@1.0.0
libA@1.0.0

What is the expected behavior? The included modules should be:

libA@2.0.0
depA
depB
libA@1.0.0

Please mention other relevant information such as the browser version, Node.js version, webpack version and Operating System. webpack@3.5.5

I have run npm dedupe but it can’t fix the problem. This is understandable, because npm doesn’t have anywhere to “put” this lower-version dependency that is shared by both depA and depB. Previously I believe this was solved with the DedupePlugin which has since been turned into a no-op.

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:26
  • Comments:31 (7 by maintainers)

github_iconTop GitHub Comments

13reactions
franjohn21commented, Dec 15, 2017

It doesn’t look like it was ever provided, so I created a repo that shows a simple example of this issue: https://github.com/franjohn21/dedupe-example

FWIW the code being webpacked in that example does not use harmony modules, so ideally webpack 2/3 could maintain parity with webpack 1.

We consistently see higher (>10%) bundle sizes in production apps at NerdWallet when migrating from webpack 1 -> webpack 3 mostly due to this issue.

9reactions
tomhicks-bsfcommented, Aug 29, 2017

Thing is, I didn’t choose to install the package twice, and there is no way for me to “fix” this at the package manager level, as you’ve suggested in other issue threads.

Wepback used to solve this problem in v1 with DedupePlugin, so this seems like a regression of sorts. The docs say that the DedupePlugin is no longer needed, which implies that it will do some kind of deduping of its own.

Read more comments on GitHub >

github_iconTop Results From Across the Web

npm-dedupe
Running npm dedupe will cause npm to note the duplication and re-evaluate, deleting the nested c module, because the one in the root...
Read more >
node.js - Duplicate modules in nested structure of node ...
I think this structure gives rise to a lot of duplicate code/modules. So would it not be a good idea if all the...
Read more >
webpack and yarn magic against duplicates in bundles
De-duplication: the process of elimination of duplicated dependencies according to their semver versions (x.x.x — major.minor.patch). Typically, ...
Read more >
Performance in Jira front-end: solving bundle duplicates with ...
First, detect all duplicated dependencies by grabbing a list of all packages within node_modules and filter those that have node_modules in ...
Read more >
pnpm/pnpm - Gitter
AFAICS using pnpm, instead of our install setup, should work just as well, and then we could still do a full copy (i.e....
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