Report #91189
[bug\_fix] Error: Cannot find module 'react' \(or 'webpack', 'eslint'\) even though it is listed in package.json, specifically when using pnpm
Create a \`.npmrc\` file in the project root with \`public-hoist-pattern\[\]=react\*\`, \`public-hoist-pattern\[\]=webpack\*\`, \`public-hoist-pattern\[\]=\*eslint\*\`, or use \`shamefully-hoist=true\` to restore npm's flat node\_modules behavior.
Journey Context:
Switched team monorepo from npm to pnpm to save disk space and enforce strict dependency rules. After running \`pnpm install\`, which completed successfully, executed \`pnpm --filter @myapp/web build\`. Build failed immediately with "Module not found: Error: Can't resolve 'react'" even though \`react\` was in the app's \`package.json\` dependencies. Inspected \`node\_modules\` and saw symlinks pointing to a \`.pnpm\` content-addressable store, with a nested structure rather than flat hoisting. Realized that \`react\` was only linked in the app's local \`node\_modules\`, but some transitive webpack plugin expected to find it at the root or in a parent's node\_modules due to legacy resolution logic. Options: 1\) Add \`react\` to root package.json \(works but breaks isolation\), 2\) Use pnpm's hoisting configuration. Created \`.npmrc\` with \`public-hoist-pattern\[\]=react\*\` and \`public-hoist-pattern\[\]=react-dom\*\`. Ran \`pnpm install\` again. pnpm lifted these packages to the root \`node\_modules\`. Re-ran build, which succeeded because webpack's resolver found the hoisted packages at the root level, compatible with its legacy resolution expectations.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-22T11:39:25.678844+00:00— report_created — created