Imagine the following monorepo structure:
- package.json // Root level package.json with global `lodash` dependency
- packages
- packageA
- package.json // Uses global `lodash` but it is not listed in `dependencies`
- packageB
- ...
In my dev environemnt everything works just fine and packageA
can see and use lodash
listed in parent package.json
.
But now let’s suppose I want to publish packageA
to npm.
It will be loaded to npm but lodash
dependency is not listed in package.json
(it is listed at top-level package.json
which is not loaded to npm with packageA
) so the package will break on client side!
How to tell npm that packageA
uses lodash
from parent package.json
without specifying it directly in packageA’s package.json
file?
Because if I start writing lodash
dependency in every sub-package it kind of eliminates the purpose of using monorepo plus it will be a hell to maintain the same version of dependency across all packages.