[Bug?]: Install location of one dependency (react-router-dom
) changes depending on version of other, unrelated dependency (@types/react
) (workspaces, monorepo, MRE attached)
#6229
Labels
bug
Something isn't working
Self-service
Describe the bug
Under certain circumstances,
yarn
is installing multiple, identical copies of a module in a monorepo when there is no reason to. This behavior is triggered by version descrepencies in modules that are unrelated to the module that's duplicated.To reproduce
This zip file contains a minimal monorepo set up as follows:
corepack
enabled and configured foryarn@stable
.yarnrc.yml
withnodeLinker: node-modules
wat_1
andwat_2
wat_1
workspace package.json depends onreact-router-dom@5
and@types/react@18
wat_2
workspace package.json depends onreact-router-dom@5
and@types/react@16
Notice: The only difference in the workspaces is the version of @types/react they depend on
cd yarn_duplicate_react_router_dom_bug
./test.sh
# Run test scriptYou should see the following output:
$ ./test.sh # (yarn installs) Expected locations of react-router-dom: ./node_modules/react-router-dom Actual locations of react-router-dom: ./node_modules/react-router-dom ./wat_2/node_modules/react-router-dom
As noted in the test, the expected behavior here is that
yarn
installsreact-router-dom
in one locatoin only,./node_modules
. If you look at the dependency graph for this monorepo, you'll see there is no overlap in the dependencies ofreact-router-dom
and@types/react
. I.e. There is no reason foryarn
to be installing multiple versions ofreact-router-dom
. Yet somehow the presence of@types/react
(and the difference in it's version) independencies
is causing the actual behavior whereyarn
also installs it in./wat_2/node_modules
.Furthermore, If you change the
@types/react
dependency inwat_2/package.json
to be the same as inwat_1/package.json
and rerun the test, you'll see that you get the expected behavior:Environment
System: OS: macOS 14.2 CPU: (10) arm64 Apple M1 Max Binaries: Node: 20.11.1 - /private/var/folders/h3/trw0qb4n5t39jdpfqnt20qy80000gn/T/xfs-4ba928f7/node Yarn: 4.1.1 - /private/var/folders/h3/trw0qb4n5t39jdpfqnt20qy80000gn/T/xfs-4ba928f7/yarn npm: 10.2.4 - ~/.nvm/versions/node/v20.11.1/bin/npm
Additional context
Possibly related:
The text was updated successfully, but these errors were encountered: