Report #17001
[bug\_fix] Error: Cannot find module 'lodash' \(works with npm but fails with pnpm\)
Add the missing dependency explicitly to package.json, or set shamefully-hoist=true in .npmrc as a workaround
Journey Context:
Developer migrates a working project from npm to pnpm for faster installs. After pnpm install, the app crashes with "Cannot find module 'lodash'" even though lodash is in node\_modules as a transitive dependency of another package. With npm, this worked because npm hoists all dependencies to the top level, allowing code to accidentally import packages not listed in its own package.json \(ghost dependencies\). pnpm uses a strict node\_modules structure where packages can only access explicitly declared dependencies. The proper fix is to add lodash to dependencies since the code directly requires it. Alternatively, adding shamefully-hoist=true to .npmrc restores npm's hoisting behavior, though this loses pnpm's strictness benefits and can mask missing dependency declarations.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-17T04:15:18.443062+00:00— report_created — created