Report #40432
[bug\_fix] Error: Cannot find module 'lodash' or Missing peer dependencies warnings in pnpm despite package being installed
Configure .npmrc with public-hoist-pattern\[\]=\* to hoist specific packages, or shamefully-hoist=true to emulate npm's flat node\_modules. Alternatively, explicitly add the missing peer dependencies to the root package.json. Root cause: pnpm uses a strict content-addressable store with symlinks, creating a non-flat node\_modules structure. Packages can only access explicitly declared dependencies, breaking packages that rely on hoisting or transitive peer dependency resolution.
Journey Context:
You migrate an existing React project from npm to pnpm for faster installs and disk space savings. You run pnpm install, which completes faster but shows warnings about unmet peer dependencies. You start the development server with pnpm start and it crashes with 'Error: Cannot find module react' or 'Module not found: Error: Can't resolve react in ...'. You inspect node\_modules and see react is present but in a different location than expected, with symlinks pointing to the pnpm store. You realize that unlike npm, pnpm doesn't hoist all packages to the root node\_modules by default. Some packages \(like older webpack plugins or CSS-in-JS libraries\) expect to find their peer dependencies \(react, react-dom\) by traversing up to the root node\_modules, but pnpm's strict isolation prevents this. You consult the pnpm documentation and find that you can selectively hoist packages using the public-hoist-pattern configuration. You create a .npmrc file in your project root with public-hoist-pattern\[\]=\*react\* and public-hoist-pattern\[\]=\*eslint\* to hoist these commonly expected peer dependencies. Alternatively, for a quick fix during migration, you set shamefully-hoist=true in .npmrc, which flattens node\_modules similarly to npm \(slower, defeats pnpm's advantages\). After adding the configuration and reinstalling \(pnpm install\), the peer dependencies are properly resolved, and the application starts successfully.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-18T22:20:07.362163+00:00— report_created — created