I, too, have noticed npm removing my symlinked in node_modules. I have many websites built with node and it would be impractical and wasteful in terms of writes to disk. So I went extreme and began making a tmpfs mount point and bind mounting that directory into my projects. But this seems wasteful in terms of bandwidth, so I settled on having a partition mounted to /node_modules and bind mounting that to various projects:
# extreme do not touch the disk mode:
#tmpfs /node_modules tmpfs noatime,nodev,nosuid,size=1400M 0 0
#
UUID="3848672deadbeef" /node_modules xfs rw,relatime,attr2,inode64,logbufs=8,logbsize=32k,noquota 0 0
/node_modules /mnt/example_sites/gatsby-theme-example/node_modules none bind 0 0
/node_modules /mnt/example_sites/example.com/node_modules none bind 0 0
/node_modules /mnt/example_sites/lovely_chickpea/node_modules none bind 0 0
With the added caveats that I often clear that node_modules directory out, usually while at home when I have good bandwidth. And I always do an npm i
when I begin working in a project. And I don't work on more than one project at the same time, I would expect issues if another npm from another project changed something's version while actively running another session elsewhere.
EDIT: Another possible solution is to keep all of your node projects in a ZFS volume and turn on deduplication.
Now proceed with all the statements of dedup in ZFS not being worth it, sucking up tons of RAM, danger will robinson, etc.
However, if you had ten very similar node projects, but needed to keep thewm separately updated with slight dependency changes and the ability to work on all at once without having to wipe some common node_modules directory and save yourself a ton of writes to disk, it may very well be worth it.