cbdeveloper
cbdeveloper

Reputation: 31495

How does yarn workspaces treat external dependencies with different versions?

Let's say a I have the following monorepo structure using Yarn workspaces:

node_modules
packages
  admin-app       // WEB APP FOR ADMIN DASHBOARD
  user-app        // PUBLIC WEB APP FOR REGULAR USERS
packages.json

Let's say both admin-app and user-app will need to install React as a dependency.

Here is what I'll do to add React on both workspaces:

yarn workspace admin-app add react
yarn workspace user-app add react

Currently, this results in both of my packages depending on "react": "^17.0.2".

Inside my root node_modules, I can see that there is only one react folder in it. And the version is, as expected, 17.0.2.

But what if at some point I update React on admin-app and maybe forget to update it on the user-app. How will yarn install those two different versions of React? For example: 17.0.5 and 17.0.2?

Upvotes: 0

Views: 1346

Answers (1)

cbdeveloper
cbdeveloper

Reputation: 31495

As a I writing this question I've decided to test it.

Here is what I did:

yarn workspace user-app add react           // THIS WILL INSTALL THE LATEST 17.0.2
yarn workspace admin-app add [email protected]

This was the result:

node_modules
  react v17.0.1
packages
  admin-app
  user-app
    node_modules
      react v17.0.2

Yarn chose to keep the older version 17.0.1 in the root node_modules folder, and it installed the 17.0.2 in the user-app/node_modules folder.

Upvotes: 2

Related Questions