I have standard Lerna
repository like this:
my-repo
- package.json
- packages
- api
- package.json
- web-app
- package.json
If I need same dependency in both packages (for example lodash
), then people in tutorials suggest to install it to both sub modules and then bootstrap project with with lerna bootstrap --hoist
flag.
Because of --hoist
flag lodash
dependency will be loaded only to root level node_modules
but both sub-modules will contain it as dependency in their appropriate package.json
But Node’s package resolution algorithm searches up the file tree looking for node_modules
folder.
So my question is why I can't just install common dependencies to root level project? Then lodash
will be located under root's node_modules
. And sub-modules (packages) will find it because Node will search up for node_module
until the root of the file system is reached.
At least it will help me to avoid using uncommon lerna bootstrap --hoist
, as well as lodash
dependency will be present only once at the top level package.json
(and not twice: in package.json
of both submodules)