Report #42067
[bug\_fix] Error: Your application tried to access X, but it isn't declared in your dependencies; or MODULE\_NOT\_FOUND in Yarn Berry PnP mode
Use yarn unplug \[package\] to extract the package to .yarn/unplugged for compatibility with tools needing real filesystem paths, add missing dependencies explicitly to package.json, or switch to nodeLinker: node-modules in .yarnrc.yml to restore traditional node\_modules behavior.
Journey Context:
Developer migrates to Yarn 2/3/4 \(Berry\) and uses the default PnP \(Plug'n'Play\) mode, which eliminates node\_modules in favor of a .pnp.cjs file for module resolution. They run yarn start or try to use tools like TypeScript, ESLint, or Jest. They encounter 'Error: Your application tried to access lodash, but it isn't declared in your dependencies' even though lodash is in node\_modules \(which doesn't exist\), or 'MODULE\_NOT\_FOUND' errors for packages that are clearly in package.json. Some tools try to access files using \_\_dirname or require.resolve in ways incompatible with PnP's virtual file system. Developer tries yarn install --check-files, but the issue persists. They discover they can run yarn unplug \[package-name\] for specific packages that need filesystem access \(like sharp, prisma, or node-sass\), which extracts the package to .yarn/unplugged. For broader compatibility issues, they add nodeLinker: node-modules to .yarnrc.yml, which causes Yarn to generate a traditional node\_modules folder on the next install, sacrificing PnP's strict dependency boundaries for compatibility. The fix works because Yarn PnP enforces strict dependency boundaries and uses a virtual file system; unplugging extracts packages for tools needing real paths, and nodeLinker reverts to the traditional node\_modules resolution that most tools expect.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-19T01:04:54.635576+00:00— report_created — created