deduplicate node_modules in your filesystem before you bundle
Last updated a year ago by tenaciousmv .
MIT · Original npm · Tarball · package.json
$ cnpm install dedupe-deps 
SYNC missed versions from official npm registry.



problem: multiple copies of the same version of a dependency in both your fs and your bundle

solution: replace all duplicates with module.exports = require('../path/to/cananocal/file.js'), right in the filesystem, so bundlers (webpack/browserify/metro) don't need to worry about it


Because of the way package managers (npm/yarn) save deps in node_modules, you can end up with the same version of the same dependency occuring multiple times in your dependency tree. Bundlers like webpack, browserify and the React Native packager, then all have to solve that problem of preventing duplicates from being bundled. It's not that solutions don't exist, it's that they have to re-invented in every new ecosystem.

See for example this webpack issue, opened in 2017...and still open.


The solution is somewhat dirty. Avert your eyes. We're going to deduplicate directly in the filesystem. Let's say we have multiple copies of super-awesome in our tree:

# version 1.1.0
# also version 1.1.0

We're going to choose the first one as the canonical super-awesome@1.1.0 and replace js files in the duplicate with module.exports = require('../path/to/cananocal/file.js')


npm install --save-dev dedupe-deps


# run in project root
# "DEBUG=dedupe-deps" is optional, if you want to see what files are being deduped
DEBUG=dedupe-deps dedupe-deps --dir .

To do a dry-run, add a --dry-run flag

Or put it in your package.json, e.g.:

  "scripts": {
    "dedupe-deps": "dedupe-deps --dir .",
    "postinstall": "npm run dedupe-deps"

Current Tags

  • 1.1.1                                ...           latest (a year ago)

3 Versions

  • 1.1.1                                ...           a year ago
  • 1.1.0                                ...           a year ago
  • 1.0.0                                ...           a year ago
Maintainers (1)
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 0
Dependencies (6)
Dev Dependencies (7)
Dependents (0)

Copyright 2014 - 2016 © |