Reputation: 78840
How do I get one monorepo package to have a dependency on another using lerna?
I have a directory structure like this in my monorepo:
packages
pkg-a (package name is @foo/pkg-a)
pkg-b (package name is @foo/pkg-b)
I want @foo/pkg-a
to have @foo/pkg-b
as a dependency, so I attempt the command:
npx lerna add @foo/pkg-b --scope=@foo/pkg-a
Lerna adds the dependency in packages/pkg-a/package.json
as expected, but it then seemingly attempts to do an lerna bootstrap
afterward, and it outputs the error:
npm ERR! 404 Not Found - GET https://registry.npmjs.org/@foo%2fpkg-b - Not found
It's completely failing to actually link to the local dependency. When npx lerna boostrap
manually afterward, I continue getting the same error.
It seems like either lerna documentation is either incredibly bad, lerna is very broken, or I'm completely missing the point of what it's supposed to let me do. How do I get one monorepo package to be linked to another using lerna?
Update
The lerna link
command seems to work to get things in the right state after the partially-failing lerna add
command. Is there a way to get lerna add
to do the right thing in the first place?
Upvotes: 0
Views: 3127
Reputation: 13781
If my-sibling hasn't been published yet you'll need to add that dependency yourself by editing the JSON file. Once the dependency is added lerna bootstrap will create the "link" regardless of whether my-sibling has been published.
The short story is that if the sibling package has not yet been published to npm you will need to manually add it to the appropriate package.json
dependencies section. From there, running lerna bootstrap
will handle the internal linking.
For instance:
// pkg-a/package.json
{
...
"dependencies": {
"@foo/pkg-b": "*"
}
}
Upvotes: 1