Report #40924
[bug\_fix] Yarn 2\+ PnP strict dependency error \(not declared in dependencies\)
Add the missing package explicitly to your project's \`dependencies\`, or use \`packageExtensions\` in \`.yarnrc.yml\` to patch the upstream package's metadata, or set \`nodeLinker: node-modules\` in \`.yarnrc.yml\` to revert to classic \`node\_modules\` behavior.
Journey Context:
Developer migrates to Yarn 2/3 for faster installs and runs \`yarn start\`. Instead of success, they get an error: \`Your application tried access lodash, but it isn't declared in your dependencies\`. The stack trace points to a package in \`.yarn/cache\`. They realize that in the old \`node\_modules\` setup, \`lodash\` was hoisted to the root and accidentally accessible to all packages \(phantom dependency\). Yarn's Plug'n'Play \(PnP\) enforces strict boundaries: a package can only import what it explicitly declares in its \`package.json\`. The developer checks the offending package and confirms it indeed forgot to list \`lodash\` as a dependency. They temporarily fix it by adding \`lodash\` to their own project's dependencies \(making it available to all\), or permanently by submitting a PR to add the missing dependency upstream and using \`packageExtensions\` in \`.yarnrc.yml\` to patch it locally until merged.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-18T23:09:45.195076+00:00— report_created — created