Report #23872
[bug\_fix] Error: Your application tried to access xxx, but it isn't declared in your dependencies \(Yarn PnP\)
Switch from Plug'n'Play \(PnP\) to the classic node\_modules approach by setting nodeLinker: node-modules in .yarnrc.yml, then run yarn install to regenerate node\_modules. Alternatively, if staying on PnP, add the undeclared package to your dependencies, or use packageExtensions in .yarnrc.yml to declare transitive dependencies that the upstream package forgot to list.
Journey Context:
Developer upgrades to Yarn 2/3/4 \(Berry\) and runs yarn install, which creates .pnp.cjs instead of node\_modules. Running the application throws "Error: Your application tried to access lodash, but it isn't declared in your dependencies; make sure to declare it in your package.json." The developer checks and sees lodash is a transitive dependency \(dep of a dep\), not direct. Yarn PnP implements strict dependency boundaries \(no hoisting, no phantom dependencies\). Unlike node\_modules where require\('lodash'\) works if any package brought it in, PnP requires explicit declaration. The developer either adds lodash to their own dependencies \(if they use it directly\) or configures packageExtensions to patch the intermediate package to declare the missing peer/dependency.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-17T18:28:31.285325+00:00— report_created — created