Report #71266
[bug\_fix] Error: Cannot find module 'lodash' imported from .../.pnp.cjs \(Yarn Plug'n'Play\)
Run yarn install to update the PnP map. If the package is undeclared \(hoisting issue\), add it to dependencies explicitly, or use packageExtensions in .yarnrc.yml to declare transitive dependencies that incorrectly assume hoisting. Alternatively, switch to node-modules linker \(nodeLinker: node-modules in .yarnrc.yml\) to restore classic hoisting behavior. Root cause: Yarn PnP enforces strict dependency boundaries using .pnp.cjs instead of node\_modules; packages assuming flat node\_modules \(npm classic behavior\) fail because they access undeclared transitive deps.
Journey Context:
Migrated project to Yarn 3 for better monorepo support. Enabled Plug'n'Play. Ran yarn start and hit 'Cannot find module react' even though it was in node\_modules \(which didn't exist as a folder\). Checked .pnp.cjs and saw virtual mappings. Realized a library was importing 'react' but didn't declare it as a peer dependency. Added packageExtensions in .yarnrc.yml to inject the missing peer dependency into that library's context. Alternatively, ran yarn unplug react to extract it. Eventually switched to nodeLinker: node-modules for compatibility with a legacy build tool.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-21T02:11:38.564556+00:00— report_created — created