Both a and b depend on c version 1.0.0, but since there's a version 2.0.0 in the root node_modules folder c can't be placed there, and has to be duplicated in a and b's own node_modules folder, otherwise Node couldn't find it for each of them.
I've built a fairly hacky solution to this before (for a different package manager) - it can be pretty simple:
node_modules/
versions/
a@1.0.0
node_modules/
c -> ../../c@1.0.0
b@1.0.0
node_modules/
c -> ../../c@1.0.0
c@1.0.0/
c@2.0.0/
a -> versions/a@1.0.0
b -> versions/b@1.0.0
c -> versions/c@2.0.0
Comments
It's actually not possible due to the way Node looks up dependencies. You could have a situation like:
Both a and b depend on c version 1.0.0, but since there's a version 2.0.0 in the root node_modules folder c can't be placed there, and has to be duplicated in a and b's own node_modules folder, otherwise Node couldn't find it for each of them.It's entirely possible with symbolic links. https://github.com/rstacruz/pnpm
You could use links, version in names, ... You'd just have problem to take out one submodule I guess, but I doubt that's a use case anywhere.
I've built a fairly hacky solution to this before (for a different package manager) - it can be pretty simple:
Some other people have linked to npm alternatives ied and pnpm which do essentially this.