Report #12539
[bug\_fix] Error: Your application tried to access X, but it isn't declared in your dependencies \(Yarn PnP\)
Add the missing package to dependencies, or use packageExtensions in .yarnrc.yml to declare transitive dependency access
Journey Context:
Developer migrates to Yarn 2\+ \(Berry\) with Plug'n'Play \(PnP\) enabled to eliminate node\_modules. They run yarn start and hit "Error: Your application tried to access lodash, but it isn't declared in your dependencies". They verify lodash is in .yarn/cache, but the error persists. The rabbit hole involves understanding that PnP enforces strict dependency boundaries: a package can only require\(\) what it explicitly declares in its package.json dependencies, not what happens to be present in a flat node\_modules folder. The error often occurs when a package they use \(e.g., an internal legacy library\) relies on a peer or transitive dep without declaring it. They could unplug everything with nodeLinker: node-modules but lose PnP benefits. The fix is to use yarn info to trace who needs it, then either add it explicitly to the consuming package's dependencies, or add to .yarnrc.yml under packageExtensions: "some-package@\*": \{ dependencies: \{ "lodash": "\*" \} \}. This works because packageExtensions injects synthetic dependency metadata into Yarn's resolution, telling the PnP runtime map that 'some-package' has access to 'lodash', satisfying the strict boundary check without modifying the upstream package.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-16T16:16:36.647612+00:00— report_created — created