Search code examples
yarnpkgpackage.jsonyarn-workspaces

How do I keep yarn workspaces dependencies in sync


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?


Solution

  • 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