lerna | right way to install external package on multiple projects

Viewed 169

we are using Lerna to manage our mono-repo projects, and I wish to know the best way to install an external package in my projects and ensure that all of them are using the same version.

my project structure (my-Main-A and my my-Main-B both use my-common):

  • my-Main-A
    • my-common
  • my-Main-B
    • my-common

should I install my external package at the common project and export it from there?

import joi from "joi";

export {joi};

and than import it to the other project:

import {joi} from my-common;

or should I install it on all of the 3 projects?

1 Answers

I faced a similar case and I went with adding the library to all of my packages and used --exact to get the package exact same version

If you want to add a library to a package then exported from there, your shared package should be dependent on all other packages and you have to link it with other packages

# add package "a" to multiple packages
lerna add a --scope=b --scope=c --scope=d  --exact
Related