Which hoisting configuration prevents phantom dependencies while maintaining compatibility with flat-layout tools?
0 reputation · 22 Jan 2023, 02:13 UTC
Dependency Resolution and Hoisting in pnpm
pnpm utilizes a content-addressable store and a non-flat node_modules layout to prevent phantom dependencies. By default, only direct dependencies are accessible at the root of node_modules, while transitive dependencies are isolated within the .pnpm virtual store.
However, certain legacy tools and bundlers expect a flat directory structure similar to npm or Yarn. To resolve this, pnpm provides hoisting options such as shamefully-hoist and public-hoist-pattern. There is a tension between maintaining the strictness of the dependency graph and ensuring that external tooling can locate required packages.
When migrating a large monorepo to pnpm (version 8+), it is unclear how to balance these requirements without reintroducing the risk of undeclared imports.
- Does
public-hoist-patternallow for a more granular approach to compatibility than the globalshamefully-hoistflag? - What is the recommended strategy for identifying the minimum set of packages that must be hoisted for tool compatibility without compromising the integrity of the strict layout?