Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Are there any advantages to using Lerna with Yarn workspaces?

We're in the process of migrating our monorepo to use Lerna.

Lerna supports both NPM and Yarn and furthermore allows configuration of use with Yarn workspaces. It's unclear to me whether Lerna with Yarn workspaces has any distinct advantages to Lerna with NPM. Many posts claim that Lerna does more or less the same thing as Yarn workspaces out of the box.

Are there any advantages to using Lerna with Yarn workspaces opposed to Lerna with NPM?

like image 825
axelyung Avatar asked Sep 05 '18 09:09

axelyung


People also ask

Why should I use lerna?

Lerna allows teams to build libraries and apps in a single repository called a monorepo. Since we don't have to publish to NPM until we're ready to go, it's faster to iterate locally when building components that depend on each other.

Do we still need lerna?

This array then needs to be maintained manually to reflect the monorepo topology. Because of this, Lerna still plays a significant role here. Lerna will determine which packages have build npm script defined, and then it determines the proper execution order.

Is lerna deprecated?

But surprisingly many still haven't heard that Lerna is back, far from obsolete or deprecated and is getting brand new features. We from Nrwl are the creators of Nx and given our long history in the monorepo space, we offered to take over stewardship of Lerna when it was declared “dead” in April 2022.

What is yarn lerna?

Lerna is used to optimize the management of monorepos. We'll use this tool to manage shared dependencies. Yarn Workspaces is used to optimize and link different packages together.


2 Answers

As far as I know, NPM doesn't have any mechanism comparable to Yarn workspaces.

Lerna + Yarn workspaces begins to shine when developing a library, as opposed to an application, however, I find that even with an application, this combination can make the local developer experience better by providing conveniences such as release management and the ability to easily define and run 'root' scripts across all or a select 'scope' of packages in the project.

like image 85
Peter Avatar answered Jan 02 '23 04:01

Peter


After some investigation, I've found the following differences:

  1. Using NPM results in a package-lock.json file for each package where using Yarn only creates one in the root of the project.
  2. Yarn workspaces seems to have better support for resolving possible conflicts in the dependency tree (given that dependencies are declared in the module where they are used, see this issue)
like image 33
axelyung Avatar answered Jan 02 '23 04:01

axelyung