How to Release a Monorepo With lerna version and lerna publish
lerna version bumps changed packages and creates git tags; lerna publish then ships those tagged versions to the registry.
Lerna detects which packages changed since the last release, bumps them (from prompts or conventional commits), commits, tags, and pushes with lerna version. lerna publish from-git then publishes exactly the tagged versions.
Steps
- Set
versionmode inlerna.json(independentor a fixed version string). - Run
lerna version --conventional-commitsto bump, tag, and push. - Run
lerna publish from-gitto publish the tagged versions. - Provide
NODE_AUTH_TOKENso publish can authenticate to npm.
lerna.json
lerna.json
{
"version": "independent",
"npmClient": "pnpm",
"command": {
"version": {
"conventionalCommits": true,
"createRelease": "github"
}
}
}Terminal
Terminal
# Bump, changelog, tag, and push in CI
npx lerna version --conventional-commits --yes
# Publish exactly what was just tagged
npx lerna publish from-git --yesGotchas
from-gitpublishes the versions in the tags Lerna just created, avoiding a second bump.- Independent mode tags each package as
name@x.y.z; fixed mode uses a singlevX.Y.Ztag.
Related guides
How to Create Per-Package Git Tags in a MonorepoTag each released package independently with a name@version tag so history and GitHub releases map to the rig…
How to Choose Independent vs Fixed Versioning for a MonorepoCompare independent versioning (each package moves on its own) with fixed or locked mode (all packages share…