Back

JSBits #6: Lerna vs. Yarn workspaces

Captain's log, stardate d75.y38/AB

Javascript ES6 Development
-
Full-stack developer
JSBits #6: Lerna vs. Yarn workspaces

The other day, one of our developers messaged me on Slack about a tool called Lerna. I've recommended yarn workspaces over Lerna in the past but now I want to be more specific about why.

My general take is:

Use yarn workspaces if you're building something with several packages (like a big application) but, if you intend to publish that packages into a registry (like a library or a framework) use lerna instead.

Splitting the code into small modules is a great way to write clean, decoupled, high quality and well-tested code. The JavaScript ecosystem knows it well. But - surprise! - it has its drawbacks.

At development time, you have to keep up to date the dependencies of each module with each other in order to "see" the changes. That's what yarn workspace and lerna do. In short, they put symlinks inside node_modules, so when you modify a package, the dependent packages can see it.

But there's another problem: when a package A depends on a package B that increases its version number (because it's modified), then package A should change the version number, too. Coordinating several changing version numbers is hard, and that's what lerna is designed for.

Happy monorepo hacking!

Share this post

Related Articles

How to build a Node.js API (part one)

How to build a Node.js API (part one)

We want to share with you how we built a Node.js API for a client, describing some patterns and javascript conventions we used.

Read full article
How to build a Node.js API (part two)

How to build a Node.js API (part two)

We want to share with you how we built a Node.js API for a client, describing some patterns and javascript conventions we used.

Read full article
JSBits #2: Return more than one value

JSBits #2: Return more than one value

Here's another JavaScript bits we wanted to share with you. Small tips and tricks for JavaScript developers for all levels. This time around, we share how to return more than one value.

Read full article