Lerna — Replacing the Bootstrap Command

Lerna v7 removes the package management commands bootstrap, add, and link. You can find more details on these changes Lerna’s 7.0.0 changelog entry.

The Lerna team encourages you to use your package manager’s functionalities to manage project dependencies. All major package managers (NPM, Yarn, PNPM, …) work seamlessly with workspaces and you don’t necessarily need Lerna anymore for the package linking. You can use NPM workspaces instead.

This tutorial shows you how to replace Lerna’s bootstap command by using workspaces.

Lerna Series Overview

Use NPM Workspaces

You should migrate to workspaces if you relied on Lerna’s functionality to install and link package dependencies in your monorepo. Using workspaces is easy by adding a workspaces entry in your package.json file.

Here’s a simple workspaces configuration in your package.json file:

{
  "name": "your-package-name",
  "version": "1.0.0",

+ "workspaces": [
+   "./packages/*"
+ ],
}

You may also have a look at NPM’s docs on workspaces for more details.

From here, you can use npm install in the root of your monorepo instead of running lerna bootstrap to install the dependencies of all packages:

# before
lerna bootstrap

# with NPM workspaces
npm install  

With Lerna, you had a node_modules folder in each of your package’s directories. When using your NPM workspaces, you’ll find a node_modules in the root of your project and none in the package’s directories. NPM does all the linking between packages for you.

You can also remove a possibly configured lerna bootstrap script from your package.json file:

{
  "name": "your-package-name",
  "version": "1.0.0",

  "scripts": {
-   "bootstrap": "lerna bootstrap",
  },

+ "workspaces": [
+   "./packages/*"
+ ]
}

Enjoy running npm install in your monorepos (instead of lerna bootstrap)!


Mentioned Resources

Explore the Library

Find interesting tutorials and solutions for your problems.