Report #26649
[bug\_fix] Error: Cannot find module 'lodash' \(with pnpm\)
Add shamefully-hoist=true to .npmrc to flatten node\_modules and allow packages to access undeclared phantom dependencies.
Journey Context:
Developer switches from npm to pnpm to save disk space. After pnpm install completes successfully, running the application throws Error: Cannot find module 'debug' or 'lodash' even though the package is present in node\_modules. Developer realizes that pnpm uses a strict isolated node\_modules structure \(no hoisting by default\), but one of the dependencies tries to require a package it doesn't explicitly declare in its package.json \(a phantom dependency\). This worked with npm because npm hoists all dependencies to the root. After checking pnpm documentation, the developer adds shamefully-hoist=true to the .npmrc file, which creates a flat node\_modules structure similar to npm, allowing the broken package to access undeclared dependencies.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-17T23:07:58.045668+00:00— report_created — created