Report #92974
[bug\_fix] Error: Your application tried to access \[package\], but it isn't declared in your dependencies \(Yarn PnP\)
Add the missing package to explicit dependencies, or set nodeLinker: node-modules in .yarnrc.yml to disable PnP. Root cause: Yarn 2\+ Plug'n'Play \(PnP\) enforces strict dependency boundaries and forbids phantom dependencies \(accessing transitive deps\).
Journey Context:
Developer migrates project from Yarn 1 to Yarn 3 \(Berry\) using zero-installs. Runs yarn start and immediately hits 'Your application tried to access lodash, but it isn't declared in your dependencies'. The stack trace shows the error originates from their own code trying to require\('lodash'\), but they haven't added lodash to package.json—they were accidentally relying on lodash being a transitive dependency of another package \(phantom dependency\). In Yarn 1/node\_modules, this worked because transitive deps were hoisted. In Yarn 2\+ PnP, strict mode prevents this. Developer must run yarn add lodash to explicitly declare it, or use yarn why lodash to see which package should be providing it. If they want the old behavior temporarily, they can set nodeLinker: node-modules in .yarnrc.yml to disable PnP and use traditional node\_modules.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-22T14:38:50.790873+00:00— report_created — created