This document contains solutions for certain issues our users encountered in the past while using Lerna.
Error when using yarn as an npm client
Prior to the release of Lerna
v2.0.0-rc.3 users of the flag
who provided yarn as a client may have suffered from the bootstrap process
not being able to run properly.
Error running command.
error Command failed with exit code 1.
If you can upgrade Lerna to said version please do so, or as an alternative
solution you can add
Private npm registry (Artifactory, npm Enterprise, etc.) integration issues
lerna bootstrap is failing because you have repositories on a private server make sure you are including that registry. Example:
lerna bootstrap -- --registry=http://[registry-url].
Buffer problems during import
When you try to import a repository which has many commits in it there is a chance that you get an error such as:
DeprecationWarning: Unhandled promise rejections are deprecated
Error: spawnSync /bin/sh ENOBUFS during ImportCommand.execute
lerna import with the
--max-buffer flag and provide a large enough
number (in bytes). At the writing of this entry the underlying default is
10MB, so you should keep this in mind.
Merge conflict commits cannot be imported
When you try to import a repository that contains merge commits that needed conflict resolutions, the import command fails with an error:
lerna ERR! execute Error: Command failed: git am -3
lerna ERR! execute error: Failed to merge in the changes.
lerna ERR! execute CONFLICT (content): Merge conflict in [file]
lerna import with the
--flatten flag to import the history in "flat"
mode, i.e. with each merge commit as a single change the merge introduced.
Failing when git tree has uncommitted changes
You will receive
fatal: ambiguous argument 'HEAD': error, when the current project has uncommitted changes.
Make sure to commit all the changes you have in your lerna project, before importing any packages using
Publish does not detect manually created tags in fixed mode with Github/Github Enterprise
Github and Github Enterprise use lightweight Git tags when a release is created through the web ui, while Lerna uses annotated tags.
This can cause an issue where Lerna will ignore previously published releases which have been manually performed and tagged with the Github web ui.
For example if the publish history was as follows:
- v1.1.0 was published and tagged with
- v1.2.0 was manually published and tagged with the Github web ui
- v1.2.1 was manually published and tagged with the Github web ui
lerna publish now would detect v1.1.0 instead of v1.2.1 as the last released tag.
The implications of this depends on your usage of
- The publish prompt would use v1.1.0 as the base for major/minor/patch suggestions.
- When using the --conventional-commit flag:
- would suggest a semver increment based on all the commits since v1.1.0 (including commits from v1.2.0, v1.2.1 etc)
- The generated CHANGELOG.md files will repeat all the commits that have already been released in v1.2.0, v1.2.1 etc
If possible, use
lerna publish over manual releases.
For new manual releases, use
git tag -a -m <version> instead of using the Github web ui.
For existing lightweight tags, they can be converted to an annotated tag using something like this:
GIT_AUTHOR_NAME="$(git show $1 --format=%aN -s)"
GIT_AUTHOR_EMAIL="$(git show $1 --format=%aE -s)"
GIT_AUTHOR_DATE="$(git show $1 --format=%aD -s)"
GIT_COMMITTER_NAME="$(git show $1 --format=%cN -s)"
GIT_COMMITTER_EMAIL="$(git show $1 --format=%cE -s)"
GIT_COMMITTER_DATE="$(git show $1 --format=%cD -s)"
git tag -a -m $1 -f $1 $1
git push --tags --force
See this Stackoverflow post for more details
Publishing to a private npm registry (Artifactory, npm Enterprise, etc)
lerna publish is failing ensure you have the following your
You may also need to add the following to your
.npmrc file on the individual package(s):
registry = https://[registry-url]
Jest / Visual Studio Code Debugging
It is possible to debug Jest tests in a Lerna-managed package using Visual Studio Code. Debugging with breakpoints works with the vscode launch configuration below in the monorepo's
<root>/.vscode/launch.json file. This example launches Jest for a single package
my-package located in the monorepo.
"name": "Jest my-package",
--runInBandavoids parallelizing tests across multiple processes
--no-cachehelps avoid caching issues
Tested with Visual Studio Code v1.19.3 and Jest v22.1.4.