javascriptmonorepolernanrwl-nxnrwl

the difference between nx and Lerna ? (monorepos)


hello i'm in new in monorepos world and i'm now searching about different monorepos tools and i found two intersting tools Nx(nrwl) and lerna but i didn't understand the real differnce between these two tools so any help and thanks


Solution

  • 2022 Update

    As pointed out by my great fellow at the comment section, Lerna is now being held by the Nx team.

    The best solution nowadays is to use more native approaches for publishing (as NPM/YARN workspaces) or go straight to Nx.

    Good references:

    2021 Answer (slightly outdated but still valid)

    Although both are great tools to work with mono repo, they're quite different in their purpose.

    Differences

    Lerna is focused on linking multiple packages from the same project and managing npm publishing, and that's about it.

    Nx is more focused on managing development workflow for multiple packages. It means it can scaffold packages, and for every package, you can define configurations on how to run and build them, in a similar manner to Webpack.

    Nx can also work to spawn multiple processes at once. For example: run frontend and backend at the same time, without the need to open two different terminals. Similar to docker-compose.

    Where they thrive

    Lerna fits better for open source projects with multiple packages (because you can easily publish your packages).

    Nx fits better for handling complex workflows with multiple packages.

    How to choose

    Someone can wonder if you could choose both, but I don't think they can work well together. At the time I'm writing this, Nx doesn't seem to care about being compatible with Lerna, and it Nx still lacks support for easy publishing.

    An important disclaimer about terminology