-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Support peer dependencies when symlinking in development #604
Description
In development, when I create a manual symlink or run npm link from my app, if my linked module has a peer dependency, using --preserve-symlink would allow the linked module to use my app's dependency instead of its local dependency.
Some modules like plugins and frameworks require using a common module instance. But without --preserve-symlink there is no way for them to share the same module instance, except by passing the instance of it at runtime.
Pnpm appears to not support --preserve-symlinks as it relies on searching for a node_modules dir one level up from its realpath to find its development dependencies.
package/index.js
package/node_modules <- doesn't exist, but normally would
node_modules/
Without --preserve-symlinks the search paths would be:
foo/node_modules/.resolutions/registry.npmjs.org/peer/4.11.2/package/node_modules
foo/node_modules/.resolutions/registry.npmjs.org/peer/4.11.2/node_modules <-- local deps first
foo/node_modules/.resolutions/registry.npmjs.org/peer/node_modules
foo/node_modules/.resolutions/registry.npmjs.org/node_modules
foo/node_modules/.resolutions/node_modules
foo/node_modules/node_modules
foo/node_modules/
With --preserve-symlinks the search paths would be:
foo/node_modules/.resolutions/registry.npmjs.org/peer/4.11.2/package/node_modules <-- doesn't exist
app/node_modules
With symlinking and --preserve-symlinks it was possible, but now with this new structure it seems impossible.
I don't see a solution to the peer dep problem without supporting --preserve-symlinks. The only other solution is to use a require hack to resolve to the correct modules at runtime.
Also, want to note that NODE_PRESERVE_SYMLINKS landed in 7.1. nodejs/node#8749
Metadata
Metadata
Assignees
Labels
Type
Projects
Status