I am working on a monorepo with 2 packages, say child and parent, initially not dependent on each other and already published to registry.
However, when I add inter-package dependency, lerna version command fails.
- npm workspaces was provided in root
package.json - useWorkspaces was provided in
lerna.json
All was fine, till I decided to add package parent as dependency of package child.
packages/child/package.json was updated like so:
{
"name": "child",
"version": "0.1.13",
"description": "this package is being updated to depend on parent",
"main": "dist/index.js",
"dependencies": {
"parent": "*" // I added this
}
}
I had updates to both child and parent. Lets say published versions of parent was 0.2.13 and child was 0.1.13 prior to update.
npm install and the symlinks worked.
Build was successful.
During version however, after prompting for version bump with conventional-commits, lerna attempts npm install command and fails due to package parent version 0.2.14 being not available in npm remote registry.
It will not be available, as this version is going to be published only now.
On version command (i am using conventional-commits),
- Lerna asked if
parent -> 0.2.14andchild -> 0.1.14was okay, it was.. - Lerna updated the
package.jsonof packagechildto be as follows:
{
"name": "child",
"version": "0.1.14", // lerna changed this
"description": "this package is being updated to depend on parent",
"main": "dist/index.js",
"dependencies": {
"parent": "^0.2.14" // lerna changed this
}
}
- Lerna updated the
package.jsonof packageparentto be as follows:
{
"name": "parent",
"version": "0.2.14", // lerna changed this
"description": "this package will be dependency of child",
"main": "dist/index.js",
}
- Lerna tried to do
npm installon bothchildandparentpackages
This fails with reason being package parent version 0.2.14 is not yet available to install, since its just going to be published now.
I followed this https://lerna.js.org/docs/getting-started. It says
The "header": "*" and "footer": "*" tell Lerna to link the contents of the header and footer as if they were published to the registry.
I was expecting the lerna version command to work and create new version commit and tag as it was doing before I added inter-package dependencies using "*".
Should I be publishing parent first with new version 0.2.14 and then update child to point to this ?
If that is the case, should I always publish parent first whenever there are breaking changes. ?
What is the right way to do this ?
PS: Looks like it fails here: https://github.com/lerna/lerna/blob/main/commands/version/index.js#L634
Should I just remove package-lock.json from root ?