Workspaces & peer deps
Consider the workspaces below. The resulting hoisting will be something like this:
node_modules/reactwill have version 18, hoisted frompackages/webpackages/mobile/node_modules/reactcan’t be hoisted and will have version 19packages/mobile/node_modules/component-libwill be a symlink topackages/component-lib
But this tree is invalid: because the node_modules resolution algorithm always resolves symlinks before importing modules, the component-lib workspace will always require react in its version 18, even when accessed through mobile. This is despite mobile correctly providing the react dependency in version 19 through the peer dependency.
There is unfortunately no node_modules layout that can address that correctly.
packages/component-lib
Section titled “packages/component-lib”{ "name": "component-lib", "peerDependencies": { "react": "*" }}packages/web
Section titled “packages/web”{ "dependencies": { "component-lib": "workspace:*", "react": "^18" }}packages/mobile
Section titled “packages/mobile”{ "dependencies": { "component-lib": "workspace:*", "react": "^19" }}