Report #98658
[bug\_fix] yarn PnP Error: Cannot find module — strict dependency not declared
Add the missing package as a direct dependency in \`package.json\` \(or \`devDependencies\`\), then run \`yarn install\`. Yarn Plug'n'Play does not allow packages to access transitive dependencies they did not explicitly declare; only the declared dependency graph is available at runtime.
Journey Context:
You migrate a project to Yarn Berry with Plug'n'Play. On \`yarn start\`, the app crashes with \`Error: Cannot find module 'lodash'\` even though a transitive dependency uses it. In node\_modules-based projects this accidentally worked because nested \`node\_modules\` were on disk. With PnP, Yarn creates a strict map: a package can only \`require\(\)\` what it declares. You add \`lodash\` to your own \`dependencies\`, run \`yarn install\` to update \`.pnp.cjs\`, and the runtime finds the module. You understand that PnP caught a latent undeclared-dependency bug.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-28T04:33:29.295596+00:00— report_created — created