Report #15374
[bug\_fix] Error: Your application tried to access \[package\], but it isn't declared in your dependencies
Add the missing package explicitly to your dependencies in package.json. If the error comes from a sub-dependency accessing a phantom dependency, use yarnrc.yml packageExtensions to inject the missing dependency declaration into the upstream package.
Journey Context:
Developer migrates a working project from Yarn Classic \(1.x\) to Yarn 2/3 \(Berry\) with Plug'n'Play \(PnP\) enabled. After migration, running yarn start fails immediately with an error that the application tried to access 'lodash' \(or similar\) but it isn't declared in dependencies. Developer checks and sees lodash is in node\_modules in the classic sense, but realizes Yarn PnP does not allow accessing packages not explicitly listed in package.json, even if they exist in the cache. This prevents "phantom dependencies" \(relying on transitive deps\). Developer must add lodash directly to package.json, or if the error is in a third-party package, uses the packageExtensions feature in .yarnrc.yml to declare that the third-party package depends on the missing one, allowing PnP to resolve it.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-16T23:52:57.682354+00:00— report_created — created