Just use pnpm. It uses the same node_modules so you get 100% compatibility with all sorts of frameworks/build systems/IDEs, but stores all files in a single global content-addressable directory, and hardlinks everything from there (or reflinks if your filesystem supports it). It also hides indirect dependencies so you don't import them accidentally (you can still use a flattened directory if you need it).
If you install libfoo@1.0.0 and libfoo@1.0.1 and the only difference between them is a single file, the second copy will only add that file to disk.
If you then install that libfoo@1.0.0 into a hundred projects spread across your disk, no files will be copied (both reflinks and hardlinks only add a bit of filesystem metadata).