Loading source
Pulling the file list, source metadata, and syntax-aware rendering for this listing.
Source from repo
pnpm 10.x reference skill covering workspaces, catalogs, patches, peer deps, overrides, and CI/CD caching strategies.
Files
Skill
Size
Entrypoint
Format
Open file
Syntax-highlighted preview of this file as included in the skill package.
references/features-peer-deps.md
1---2name: pnpm-peer-dependencies3description: Handling peer dependencies with auto-install and resolution rules4---56# pnpm Peer Dependencies78pnpm has strict peer dependency handling by default. It provides configuration options to control how peer dependencies are resolved and reported.910## Auto-Install Peer Dependencies1112By default, pnpm automatically installs peer dependencies:1314```ini15# .npmrc (default is true since pnpm v8)16auto-install-peers=true17```1819When enabled, pnpm automatically adds missing peer dependencies based on the best matching version.2021## Strict Peer Dependencies2223Control whether peer dependency issues cause errors:2425```ini26# Fail on peer dependency issues (default: false)27strict-peer-dependencies=true28```2930When strict, pnpm will fail if:31- Peer dependency is missing32- Installed version doesn't match required range3334## Peer Dependency Rules3536Configure peer dependency behavior in `package.json`:3738```json39{40"pnpm": {41"peerDependencyRules": {42"ignoreMissing": ["@babel/*", "eslint"],43"allowedVersions": {44"react": "17 || 18"45},46"allowAny": ["@types/*"]47}48}49}50```5152### ignoreMissing5354Suppress warnings for missing peer dependencies:5556```json57{58"pnpm": {59"peerDependencyRules": {60"ignoreMissing": [61"@babel/*",62"eslint",63"webpack"64]65}66}67}68```6970Use patterns:71- `"react"` - exact package name72- `"@babel/*"` - all packages in scope73- `"*"` - all packages (not recommended)7475### allowedVersions7677Allow specific versions that would otherwise cause warnings:7879```json80{81"pnpm": {82"peerDependencyRules": {83"allowedVersions": {84"react": "17 || 18",85"webpack": "4 || 5",86"@types/react": "*"87}88}89}90}91```9293### allowAny9495Allow any version for specified peer dependencies:9697```json98{99"pnpm": {100"peerDependencyRules": {101"allowAny": ["@types/*", "eslint"]102}103}104}105```106107## Adding Peer Dependencies via Hooks108109Use `.pnpmfile.cjs` to add missing peer dependencies:110111```js112// .pnpmfile.cjs113function readPackage(pkg, context) {114// Add missing peer dependency115if (pkg.name === 'problematic-package') {116pkg.peerDependencies = {117...pkg.peerDependencies,118react: '*'119}120}121return pkg122}123124module.exports = {125hooks: {126readPackage127}128}129```130131## Peer Dependencies in Workspaces132133Workspace packages can satisfy peer dependencies:134135```json136// packages/app/package.json137{138"dependencies": {139"react": "^18.2.0",140"@myorg/components": "workspace:^"141}142}143144// packages/components/package.json145{146"peerDependencies": {147"react": "^17.0.0 || ^18.0.0"148}149}150```151152The workspace `app` provides `react` which satisfies `components`' peer dependency.153154## Common Scenarios155156### Monorepo with Shared React157158```yaml159# pnpm-workspace.yaml160catalog:161react: ^18.2.0162react-dom: ^18.2.0163```164165```json166// packages/ui/package.json167{168"peerDependencies": {169"react": "^18.0.0",170"react-dom": "^18.0.0"171}172}173174// apps/web/package.json175{176"dependencies": {177"react": "catalog:",178"react-dom": "catalog:",179"@myorg/ui": "workspace:^"180}181}182```183184### Suppress ESLint Plugin Warnings185186```json187{188"pnpm": {189"peerDependencyRules": {190"ignoreMissing": [191"eslint",192"@typescript-eslint/parser"193]194}195}196}197```198199### Allow Multiple Major Versions200201```json202{203"pnpm": {204"peerDependencyRules": {205"allowedVersions": {206"webpack": "4 || 5",207"postcss": "7 || 8"208}209}210}211}212```213214## Debugging Peer Dependencies215216```bash217# See why a package is installed218pnpm why <package>219220# List all peer dependency warnings221pnpm install --reporter=append-only 2>&1 | grep -i peer222223# Check dependency tree224pnpm list --depth=Infinity225```226227## Best Practices2282291. **Enable auto-install-peers** for convenience (default in pnpm v8+)2302312. **Use peerDependencyRules** instead of ignoring all warnings2322333. **Document suppressed warnings** explaining why they're safe2342354. **Keep peer deps ranges wide** in libraries:236```json237{238"peerDependencies": {239"react": "^17.0.0 || ^18.0.0"240}241}242```2432445. **Test with different peer versions** if you support multiple majors245246<!--247Source references:248- https://pnpm.io/package_json#pnpmpeerdependencyrules249- https://pnpm.io/npmrc#auto-install-peers250-->251