Same package appearing in multiple places gets included multiple times
See original GitHub issueDo you want to request a feature or report a bug?
A bug
What is the current behavior?
See the repo to reproduce the issue: https://github.com/yachaka/webpack-duplicate-module-issue Having the following folder structure,
webpack.config.js // entry: package1/index.js
package1/
package.json // dependency: lodash@4.17.4
index.js // import package2 from '../package2'
package2/
package.json // dependency: lodash@4.17.4
index.js
With the files package1/index.js
and package2/index.js
being:
package1/index.js
const _ = require('lodash');
require('../package2/');
package2/index.js
const _ = require('lodash');
Lodash gets included 2 times, even though it is the same version that is installed in both package. I though this was intended to be deduped.
If the current behavior is a bug, please provide the steps to reproduce.
- Get the configuration as provided above (https://github.com/yachaka/webpack-duplicate-module-issue)
- run webpack
- notice lodash is included 2 times in the bundle, with both time the same version
What is the expected behavior?
lodash gets included only one time as the version in both package.json is the same
If this is a feature request, what is motivation or use case for changing the behavior? /
Please mention other relevant information such as the browser version, Node.js version, webpack version and Operating System. Mac Sierra 10.12.5 node.js 8.1.4 webpack 3.4.1
Issue Analytics
- State:
- Created 6 years ago
- Comments:10 (1 by maintainers)
I’m also trying to solve this. I was under the impression that Webpack did de-dupe these. The only way I have gotten it to work is having a peer dependency in the package2
package.json
, ensuring that those peer dependencies are installed in package1’snode_modules
and aliasing them in thewebpack.config.js
so the imports in both packages resolve properly when bundled. However, this also means that package1 has fake dependencies because if there is a shared dependency for package2 and a package3, package1 would also have to have that installed even if it doesn’t actually use it. It feels like if we are already in a build step this should be de-dupedcan you post yarn config.