Hi everyone I have a qu…

1 minute read

Hi everyone, I have a question around managing dependencies between apps and libs. Is it possible to have dependencies scoped to a library? or is that an an anti-pattern in Nx ?

For e.g. if I have a libs/foo and libs/bar and in libs/foo want to use lodash v3.x.x but libs/bar wants to use lodash v4.x.x (which can be installed at root)

Summary: Currently the workspace has a package.json , however if i generate a publishable library using a plugin, we do have a libs/<library-name>/package.json too. If I have to install a dependency that my newly generated library wants to consume, my understanding is that we install it at root level so all libs and apps have access to it. This is good because you workspace can maintain a single version principle and all apps and libs can update dependencies at once, but can each libs have control over the dependency versions in their own package.json scope?

Please let me know?

Responses:

It seems like you already agree with the idea of keeping a single version of your dependencies. That’s the route that we’d recommend.

It is technically possible to alias a second version of a dependency in you package.json file, like this:

"some-library": "^1.0.0", "some-library-v2": "npm:some-library@^2.0.0", That will probably cause a lot of headaches though.

Thanks Issac. I am in agreement of the benefits of single version principle. Just curious to know if Nx has any docs that I can read about that list the benefits/tradeoff of this

Updated: