Yarn Berry PnP "Cannot find module" (require stack) in CI
Yarn Berry's default Plug'n'Play mode has no node_modules; resolution goes through .pnp.cjs. A tool that resolves modules the classic way, unaware of PnP, cannot find its dependencies and throws "Cannot find module".
What this error means
A build or lint step fails with "Error: Cannot find module 'X'" and a require stack, even though yarn install succeeded, because the tool bypasses the PnP resolver.
Error: Cannot find module 'eslint-plugin-react'
Require stack:
- /home/runner/work/app/app/.eslintrc.js
at Module._resolveFilename (node:internal/modules/cjs/loader)Common causes
A tool does not support Plug'n'Play
The tool resolves modules by walking node_modules, which does not exist under PnP, so it never consults .pnp.cjs.
The process was not launched through the PnP runtime
Running a binary directly instead of via yarn run skips the .pnp.cjs hook, so PnP resolution is not active.
How to fix it
Run tools through the PnP runtime
Invoke tools with yarn <tool> (or the sdk shims) so .pnp.cjs is loaded and resolution works.
yarn eslint .
yarn dlx @yarnpkg/sdks baseSwitch to the node-modules linker for stubborn tools
If a critical tool cannot support PnP, set nodeLinker: node-modules so Yarn produces a conventional layout.
nodeLinker: node-modulesHow to prevent it
- Install editor/CLI SDKs with
yarn dlx @yarnpkg/sdksso tools resolve under PnP. - Launch tools via
yarnso.pnp.cjsis active. - Choose
nodeLinker: node-modulesup front if your toolchain is PnP-incompatible.