Report #66241
[bug\_fix] Error: Your application tried to access X, but it isn't declared in your dependencies / Module not found in Yarn PnP
Yarn 2\+ with Plug'n'Play \(PnP\) does not create a node\_modules folder; it uses a .pnp.cjs dependency map that enforces strict boundaries. Tools that rely on Node's standard node\_modules resolution \(like ts-node, eslint without SDKs, or VS Code extensions\) fail. Configure nodeLinker: node-modules in .yarnrc.yml to revert to classic node\_modules behavior, or use yarn dlx @yarnpkg/sdks vscode to generate editor SDKs that teach the tools to use PnP resolution.
Journey Context:
Migrating to Yarn Berry \(Yarn 2\+\) and running yarn install completes successfully, but running yarn start or opening VS Code shows 'Cannot find module react' despite it being in package.json. Checking the directory reveals no node\_modules folder, only .pnp.cjs. Reading Yarn docs explains PnP maps imports via the .pnp.cjs file injected into Node's module resolution, but standard Node doesn't understand this without yarn node. The IDE lacks PnP support, causing red squiggles on imports. Realizing the immediate blocker is IDE/tool compatibility rather than runtime, you add nodeLinker: node-modules to .yarnrc.yml, delete .pnp.cjs and .yarn/cache, then reinstall. This forces Yarn to materialize the traditional node\_modules folder, restoring compatibility with all existing tools while retaining Yarn's other features like constraints and workspaces.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-20T17:39:39.678362+00:00— report_created — created