So here's (part of) the problem:
-
When you use
requirein Node, Node will look at the closestnode_modulesand if it can’t find it there look in the parent dir for anode_modulesinstall that has it, until it reaches/. -
When you ‘link’ npm/yarn do nothing else but create a symlink in your
node_modulesto 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
requiresomething and it can’t find it in its ownnode_moduleswhere 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.