Report #71704
[bug\_fix] Error: Cannot find module 'lodash' \(in pnpm projects\) \| MODULE\_NOT\_FOUND
Use pnpm install instead of npm install, or add shamefully-hoist=true to .npmrc for compatibility with legacy tools
Journey Context:
Developer clones a repository that uses pnpm \(evident from pnpm-lock.yaml\). Accidentally runs npm install out of habit, or deletes node\_modules and runs npm install instead of pnpm install. Alternatively, they run pnpm install but then try to use a tool that expects a flattened node\_modules \(like React Native or certain Jest configurations\). When starting the app, they get "Error: Cannot find module 'lodash'" even though lodash is in package.json. Developer inspects node\_modules and sees a non-flat structure with a .pnpm directory and symlinks. Realizes pnpm uses a strict virtual store and content-addressable store with symlinks, which is different from npm's hoisting. The module is present but not in the location the legacy tool expects. Fix: Delete node\_modules and package-lock.json \(if npm was used\), run pnpm install to restore the pnpm structure. If the tool requires hoisted dependencies, create a .npmrc file with shamefully-hoist=true and run pnpm install again, which creates a flat node\_modules similar to npm while keeping pnpm's store benefits.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-21T02:56:24.973873+00:00— report_created — created