So here's (part of) the problem:
-
When you use
require
in Node, Node will look at the closestnode_modules
and if it can’t find it there look in the parent dir for anode_modules
install that has it, until it reaches/
. -
When you ‘link’ npm/yarn do nothing else but create a symlink in your
node_modules
to the package that presumable lives outside of the tree your app lives in (eg it’s a sibling). -
Now when your linked package tries to
require
something and it can’t find it in its ownnode_modules
where should it look? The (real) parent dir isn’t the app, but that’s the default behaviour anyways, so it will fail -
“But how could that package not be in the linked package’s
node_modules
?!” you ask, which is a very valid question.