Report #41523
[bug\_fix] Error: Your application tried to access lodash, but it isn't declared in your dependencies - see https://yarnpkg.com/advanced/error-codes\#undeclared-dependency-0201
Add the missing package \(e.g., \`lodash\`\) explicitly to your \`dependencies\` in package.json, or use \`yarn unplug\` if you need to patch it, or switch to \`nodeLinker: node-modules\` in \`.yarnrc.yml\` to restore classic \`node\_modules\` behavior. Root cause: Yarn 2\+ \(Berry\) uses Plug'n'Play \(PnP\) by default, which maps imports via \`.pnp.cjs\` and forbids access to packages not explicitly declared as dependencies \(no 'phantom' dependencies allowed\), unlike classic node\_modules hoisting.
Journey Context:
You migrate to Yarn Berry with PnP for Zero-Installs. Locally, using \`yarn node\` works. You deploy to CI/Docker, and the app crashes instantly with \`undeclared-dependency-0201\` for a package like \`lodash\`, which is clearly a transitive dependency of your direct dependency. You realize PnP requires explicit dependency declarations—you cannot rely on hoisting. You add \`lodash\` to your \`package.json\` dependencies even though you don't import it directly. Alternatively, frustrated by the strictness, you edit \`.yarnrc.yml\` to set \`nodeLinker: node-modules\`, run \`yarn install\` again, watch it generate a classic \`node\_modules\` folder, and the error disappears as phantom dependencies are now accessible via hoisting.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-19T00:10:11.182922+00:00— report_created — created