How to remove duplicate npm packages if root has a different major version than dependencies

Viewed 2536

My dependency tree looks like the following:

│ ├─┬ react-component-lib@1.10.16
│ ├─┬ react-component-lib@1.10.16
│ ├─┬ react-component-lib@2.0.16
│ ├─┬ react-component-lib@1.10.16
│ ├─┬ react-component-lib@1.10.16
│ ├─┬ react-component-lib@1.10.16
│ ├─┬ react-component-lib@1.10.16
│ ├─┬ react-component-lib@1.10.16
│ ├─┬ react-component-lib@1.10.16
│ ├─┬ react-component-lib@2.0.19
│ ├─┬ react-component-lib@1.10.16
├─┬ react-component-lib@2.0.9

I don't want the react-component-lib getting pulled in so many times when I deploy my production artifact. We are using the latest version of npm and webpack to bundle our assets. We have tried using npm prune and npm dedupeand nothing. We have currently concluded that this is occurring because the root project has version 2 while the dependencies have version 1 so dedupe cant flatten the structure. Any ideas how we can solve this problem?

1 Answers

fastest way is - re-edit the package.json file , - delete node_modules folder and - run npm install

Related