How can I centralize dependecny version when using `nx` in a monorepo with `yarn4 png`?

I have a typescript monorepo managed by nx. There are about 122 projects in this repo and all written in typescript nodejs. With yarn4 pnp enabled https://yarnpkg.com/features/pnp.

There are some 3rd party dependencies used by most of the projects in this monorepo. I am looking for a way to let all projects share the same version of shared dependecnies and found nx has a suggestion that put those dependencies in root level of package.json: https://nx.dev/concepts/more-concepts/dependency-management.

However, it is not working with yarn4 pnp which requries all dependencies used by the projects need to be listed in project level package.json.

So what is the right way to enforce same dependencies' versions while keep using yarn pnp?

1 Answers

One way to centralize dependency versions while using nx in a monorepo with yarn4 pnp is to create a shared package within your monorepo. In this shared package, you can manage all the common dependencies that are used across multiple projects. Each project in your monorepo can then explicitly reference the shared package as a dependency, ensuring they all use the same versions. This approach leverages the benefits of yarn's Plug'n'Play feature while still centralizing dependency management.