Using pnpm with Lerna
Lerna can be used in a pnpm
workspace to get the full benefits of both pnpm
and Lerna.
When used in a pnpm
workspace, Lerna will:
- resolve package locations with
pnpm-workspace.yaml
(https://pnpm.io/workspaces) - ignore
"workspaces"
inpackage.json
- block usage of
bootstrap
,link
, andadd
commands. Instead, you should usepnpm
commands directly to manage dependencies (https://pnpm.io/cli/install). - respect the workspace protocol for package dependencies.
- During
lerna version
, dependencies will be updated as normal, but will preserve theworkspace:
prefix if it exists. - If a workspace alias is used, then
lerna version
will not bump the version of the dependency, since aliases don't specify a version number to bump.
- During
Getting Started
To set up pnpm with Lerna:
-
If not installed already, install
pnpm
: https://pnpm.io/installation. -
Remove the
node_modules/
folder in the root, if it exists. If not already using workspaces, runlerna clean
to remove thenode_modules/
folder in all packages. -
Set
"npmClient": "pnpm"
inlerna.json
. -
Create a
pnpm-workspace.yaml
file in the root of your project. If you are already using npm or yarn workspaces, move the "workspaces" property frompackage.json
topnpm-workspace.yaml
. If you were not already using workspaces, move the "packages" property fromlerna.json
topnpm-workspace.yaml
. For example:package.json{
"workspaces": ["packages/*"]
}and
lerna.json{
"packages": ["packages/*"]
}become:
pnpm-workspace.yamlpackages:
- "packages/*" -
(optional) Run
pnpm import
to generate apnpm-lock.yaml
file from an existing lockfile. See https://pnpm.io/cli/import for supported lockfile sources. -
Run
pnpm install
.