Report #74448
[bug\_fix] Error: tried to access , but it isn't declared in its dependencies \(Yarn PnP\)
Add the missing dependency to the consuming package's package.json dependencies, or use packageExtensions in .yarnrc.yml to declare the undeclared dependency, or switch to nodeLinker: node-modules in .yarnrc.yml to disable PnP. Root cause: Yarn Plug'n'Play \(PnP\) enforces strict dependency boundaries with no hoisting; packages cannot require transitive dependencies unless explicitly declared, catching missing dependency bugs that node\_modules hides.
Journey Context:
You migrate a project to Yarn 3 with PnP enabled. Everything installs faster and disk usage drops. But running the app throws 'Error: lodash tried to access react, but it isn't declared in its dependencies'. In node\_modules, this worked because react was hoisted to root and lodash could find it. With PnP, each package has an isolated dependency map defined by .pnp.cjs. The fix is either adding react to lodash's package.json \(if you control it\), or using the packageExtensions feature in .yarnrc.yml to inject the dependency: packageExtensions: \{'lodash@\*': \{peerDependencies: \{react: '\*'\}\}\}. For many legacy packages, switching to nodeLinker: node-modules in .yarnrc.yml restores node\_modules behavior as a last resort.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-21T07:33:41.146899+00:00— report_created — created