Report #61579
[bug\_fix] pnpm: Cannot find module 'lodash' \(ghost dependency\)
Add the missing package explicitly to package.json dependencies, or use pnpm.hooks to inject missing peer-like deps, or configure shamefully-hoist=true in .npmrc \(not recommended for new projects\).
Journey Context:
Developer migrates a working npm project to pnpm. Runs pnpm install successfully, but when starting the app gets "Error: Cannot find module 'lodash'" \(or any other package\). They inspect node\_modules and see it's structured differently - only direct dependencies are at root, everything else is in .pnpm and symlinked. They realize their code imports 'lodash' but lodash isn't in their package.json - it was previously "hoisted" to root by npm/yarn because another dependency used it \(a "ghost dependency"\). pnpm's strict node\_modules structure prevents this unsafe access. The fix is to explicitly declare all imported packages in package.json. For packages that have incorrect peer dependency declarations causing the issue, they can use pnpm.packageExtensions in .yarnrc.yml \(pnpmfile.js in older versions\) to patch the upstream package's dependencies. As a last resort for quick migration, they can set shamefully-hoist=true in .npmrc to simulate npm's flat node\_modules.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-20T09:51:02.591470+00:00— report_created — created