Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug?]: Install location of one dependency (react-router-dom) changes depending on version of other, unrelated dependency (@types/react) (workspaces, monorepo, MRE attached) #6229

Open
1 task
broofa opened this issue Apr 16, 2024 · 0 comments
Labels
bug Something isn't working

Comments

@broofa
Copy link

broofa commented Apr 16, 2024

Self-service

  • I'd be willing to implement a fix

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

  1. Download yarn_duplicate_react_router_dom_bug.zip and unzip it.

This zip file contains a minimal monorepo set up as follows:

  • corepack enabled and configured for yarn@stable
  • .yarnrc.yml with nodeLinker: node-modules
  • top-level package.json with two workspaces: wat_1 and wat_2
  • wat_1 workspace package.json depends on react-router-dom@5 and @types/react@18
  • wat_2 workspace package.json depends on react-router-dom@5 and @types/react@16

Notice: The only difference in the workspaces is the version of @types/react they depend on

  1. cd yarn_duplicate_react_router_dom_bug
  2. ./test.sh # Run test script

You 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 installs react-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 of react-router-dom and @types/react. I.e. There is no reason for yarn to be installing multiple versions of react-router-dom. Yet somehow the presence of @types/react (and the difference in it's version) in dependencies is causing the actual behavior where yarn also installs it in ./wat_2/node_modules.

Furthermore, If you change the @types/react dependency in wat_2/package.json to be the same as in wat_1/package.json and rerun the test, you'll see that you get the expected behavior:

$ cat wat_2/package.json
{
  "name": "wat_2",
  "version": "1.0.0",
  "dependencies": {
    "@types/react": "18",
    "react-router-dom": "5"
  }
}

$ ./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

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:

@broofa broofa added the bug Something isn't working label Apr 16, 2024
@broofa broofa changed the title [Bug?]: Installing identical versions of react-router-dom in multiple locations when an unrelated dependency (@types/react) has different versions (MRE attached) [Bug?]: Install location of one dependency (react-router-dom) changes depending on version of other, unrelated dependency (@types/react) (workspaces, monorepo, MRE attached) Apr 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant