Is your feature request related to a problem? Please describe.
pnpm is a mature package manager used by a significant amount of companies and it works well with almost all stacks in the ecosystem. However, because the node_modules structure created by pnpm heavily relies on symlinks, pnpm is unusable in environments that do not support symlinks:
- pnpm doesn’t work with electron apps
- an app that uses pnpm cannot be deployed to lambda
These issues of symlinks are probably the main reason neither npm nor Yarn considered to create a properly nested node_modules using symlinks.
Describe the solution you’d like
Some way to link a package from a different location using a file, not a symlink. For instance,
node_modules/foo can be a text file that contains a relative path to a different location. When
require('foo') is searching for the location of foo, the path from the text file is read and used to track down the reallocation of foo (in case of pnpm it will be something like
Describe alternatives you’ve considered
I considered Yarn Plug’n’Play. pnpm supports Yarn PnP, there’s an option that makes pnpm create and use a pnp generated via one of Yarn’s packages. I like the concept of Plug’n’Play but it still has many issues. Even more issues than symlinks.
I think Plug’n’Play would be a good solution if Node.js would natively support providing some import maps. pnpm would then generate such import maps and node would read the files directly from pnpm’s content-addressable store.
I also considered creating dummy redirect files. Instead of creating a symlink, we can create something like
module.exports = require('.email@example.com/node_modules/foo`)
However, this would not cover cases like
I also considered replacing the contents of all require/import statements during installation. So if a package is installed, which requires
foo, pnpm replaces
require('foo')with the reallocation of foo (
require('../../firstname.lastname@example.org/node_modules/foo')) in all files.
This solution would probably work in most cases but it would require a lot of new logic to be added to pnpm.
Also, it would only work in copy mode, and that would destroy all the great disk saving benefits of pnpm.