Report #96247
[bug\_fix] Error: Your application tried to access X, but it isn't declared in your dependencies \(Yarn PnP\)
Add the missing package to your project's dependencies with yarn add X, or if the import is in a dependency that forgot to declare it, use packageExtensions in .yarnrc.yml to patch the parent package's dependencies.
Journey Context:
Developer migrates an existing project to Yarn 2 or 3 \(Berry\) with Plug'n'Play \(PnP\) enabled, which is the default when no node\_modules exists. They run yarn start or yarn node server.js. Immediately they get a long error message: "Error: Your application tried to access lodash, but it isn't declared in your dependencies; this makes the require call ambiguous and unsound." The stack trace points to their code requiring a package. Developer is confused because this worked perfectly with node\_modules. They realize that PnP strictly enforces that only packages explicitly listed in package.json dependencies \(or devDependencies\) are accessible. Unlike node\_modules, which hoists all transitive dependencies to the top level allowing accidental access, PnP creates a strict dependency map. Developer checks the import in their code, confirms they are indeed using lodash but forgot to add it to package.json \(it was previously hoisted from a sub-dependency\). They run yarn add lodash. The error immediately moves to the next undeclared dependency \(perhaps uuid or react-dom\). They continue adding each missing direct dependency until yarn start runs successfully. If the error had been inside a third-party package that forgot to declare its own dependency, they would have used packageExtensions in .yarnrc.yml to patch it, but in this case, simply declaring the direct dependencies fixes the strict PnP checks.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-22T20:08:11.735337+00:00— report_created — created