Report #14015
[bug\_fix] Error: Your application tried to access \[package\], but it isn't declared in your dependencies
Add the missing package explicitly to the project's dependencies, or configure .yarnrc.yml with packageExtensions to declare the missing transitive dependency, or set nodeLinker: node-modules to revert to classic node\_modules behavior. Root cause: Yarn 2\+ \(Berry\) uses Plug'n'Play \(PnP\) by default, which enforces strict dependency boundaries; packages can only require what they explicitly declare, preventing unsafe access to hoisted transitive dependencies that worked by accident in node\_modules.
Journey Context:
A full-stack developer upgrades a Create React App project to Yarn 2 \(yarn set version stable\) to use the new Plug'n'Play features for faster installs. After the upgrade, they run yarn start. Instead of the dev server, they get a red error overlay: "Error: Your application tried to access react-router-dom, but it isn't declared in your dependencies". The developer is confused—react-router-dom is definitely in package.json dependencies. They check the stack trace and realize the error originates from a library react-router-config which is trying to require react-router-dom, but react-router-dom is not listed in react-router-config's dependencies \(it assumes hoisting\). In the old node\_modules structure, this worked because npm would hoist react-router-dom to the root. In Yarn PnP, this unsafe access is blocked. The developer considers switching back to node\_modules by setting nodeLinker: node-modules in .yarnrc.yml, but wants to keep PnP benefits. Instead, they use the packageExtensions feature in .yarnrc.yml to declare that react-router-config has a peer dependency on react-router-dom. Running yarn install again generates a new PnP map that allows the access. The fix works because it explicitly declares the dependency relationship that was previously implicit and unsafe, satisfying PnP's strict boundary checks.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-16T20:22:21.119048+00:00— report_created — created