Report #91986
[bug\_fix] Error: Your application tried to access \[package\], but it isn't declared in your dependencies \(Yarn Berry PnP\)
Add the missing package to your explicit dependencies \(even if it's a transitive dependency\), or use \`yarn unplug \[package\]\` to extract the package from the zip store to a real folder that can access unlisted dependencies \(though this defeats PnP strictness\). Alternatively, use \`yarn node\` instead of \`node\` to ensure the PnP runtime is loaded, or configure \`packageExtensions\` in \`.yarnrc.yml\` to patch the upstream package to declare its missing dependencies.
Journey Context:
You migrate your project to Yarn 2/3 \(Berry\) and run \`yarn install\`. It finishes in seconds, creating a .pnp.cjs file instead of node\_modules. You run \`node index.js\` and get an error that a package \(say, react-scripts\) is trying to access webpack, but webpack isn't declared in react-scripts's dependencies \(it's a peer/implicit dependency\). In node\_modules, this worked through hoisting, but Yarn PnP strictly forbids accessing undeclared dependencies. You try using \`yarn node index.js\` which works because it injects the PnP runtime. You realize you either need to add the missing dep to your own package.json, or use packageExtensions to fix the upstream package, or switch to \`nodeLinker: node\_modules\` in .yarnrc.yml to abandon PnP and return to classic node\_modules behavior.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-22T12:59:21.358076+00:00— report_created — created