16

Let's say I have multiple packages in my yarn workspaces.

@mycompany/utils
@mycompany/app
@mycompany/serv

Let's say each of these packages has a dependency on lodash. I want to make sure that they all have the same lodash version.

Is there a way to do that in each of the package.json?

Kenneth Truong
  • 3,882
  • 3
  • 28
  • 47
  • If this is still on the agenda, how about adding lodash to the root package.json: `yarn add lodash -W`? – Al-un May 30 '19 at 06:49
  • Yea I did that at first and realized that adding it into the root package.json isn't really a great solution because you wouldn't be able to tell which package has which dependencies later on ): – Kenneth Truong May 30 '19 at 07:12
  • I am currently facing a similar problem. If you have it solved, how did you solve it? – Al-un May 30 '19 at 08:50
  • Unfortunately.. I haven't solved it ): – Kenneth Truong May 30 '19 at 17:52
  • One thing I wanted to look into was maybe using https://dependabot.com/ since it got acquired by Github and is now free so that could help keep all dependencies up to date – Kenneth Truong May 30 '19 at 17:54
  • May it help, we are switching to real monorepo architecture. We use Yarn workspaces and Lerna. With `lerna add lodash`, it adds lodash to all packages. The only trick I found to guarantee that dependencies have the same version everywhere is to remove it (Maybe `lerna exec -- yarn remove lodash) and re-add it `lerna add lodash@x.y.z`. – Al-un Jul 15 '19 at 13:55

1 Answers1

10

Use syncpack to force all sub-packages in a monorepo uses the same version of each dependency.

Install in the root package.json:

yarn add --dev -W syncpack

Run (Recommnded: Run on every commit using husky):

syncpack list-mismatches

More info: https://github.com/JamieMason/syncpack

Stav Alfi
  • 13,139
  • 23
  • 99
  • 171