The pnpm Link Trap: Hard Links, Symlinks, and Why Your Build Breaks
If your pnpm-based project suddenly fails in Electron, React Native, or a Serverless deploy with "module not found" or a white screen, the cause is likely symlink packaging, not your code. One line in .npmrc flips the layout and fixes it.
pnpm's disk-saving trick is a two-layer link scheme. It stores one copy of everything in a global store, then hard-links individual .js files into each project's .pnpm directory. Since hard links can't point to folders, pnpm drops a directory symlink at node_modules/react to redirect Node.js. That works for ordinary web apps, but anything that walks node_modules without following symlinks hits a wall.
React Native's Metro bundler, electron-builder when packing .asar archives, and Serverless deployment scripts that use simple copy/zip commands all choke on the symlinks. The common workaround, shamefully-hoist=true, doesn't help because it just adds more symlinks. The real switch is node-linker=hoisted, which abandons the virtual store and flattens node_modules back to a traditional layout.
This is an OS fundamentals story: hard links share an inode and die when the last reference goes; symlinks are paths that go stale. pnpm's design leans on both, and knowing which tool expects what saves you a day of debugging.
pnpm's space savings come at the cost of a nonstandard node_modules layout; the breakage shows up exactly where tools don't honor symlinks.
The common fix, shamefully-hoist=true, is a red herring for symlink issues because it adds symlinks rather than removing them.
Going back to a flattened layout via node-linker=hoisted trades disk space and isolation for compatibility, a reasonable trade only when the target toolchain demands it.
The thread offers one practical mitigation: run a dependency-loading test on the packaged output. A follow-up asks what to do when that test finds a problem, a question the article doesn't address. The rest is agreement with the core explanation, especially the hard-link/symlink distinction and the React Native and Windows failure modes.
Run a dependency-loading test after packaging.
What do you do if the test finds a problem?
Finally someone explained the hard-link and symlink thing clearly. Once directory entries and data blocks are separated, pnpm's whole approach immediately makes sense. The points about React Native and Windows pitfalls are well aimed; after reading, I feel confident.
People who've encountered it will remember it more deeply after reading.