---
name: managing-pnpm-dependencies
description: Manage Node.js dependencies with pnpm - workspaces, catalogs, workspace protocols, build-script approval with allowBuilds, hoisting, and frozen installs in CI. Use when editing package.json dependencies or pnpm-workspace.yaml, adding or removing packages, or fixing an install error.
license: MIT
compatibility: Requires pnpm 10 or later, pinned in packageManager. Tested with pnpm 12.
metadata:
author: famiglio
category: tooling
---
# Managing pnpm Dependencies
Install packages fast, and keep the versions of a project, or of every package of a monorepo, consistent.
## Prerequisites
- `package.json` pins pnpm in `packageManager`, such as `"packageManager": "pnpm@12.26.0"`. Use that version: run `corepack enable`, or install it.
- Read `pnpm-workspace.yaml` if it exists. It holds the settings, the workspace packages, and the catalog.
## Procedure
1. **Add a dependency to the package that uses it**, never to the root of a monorepo unless only the root uses it:
```bash
pnpm --filter @acme/web add -D vitest
```
2. **Keep shared versions in the catalog** of `pnpm-workspace.yaml`, and reference them with `catalog:`. A single-package project can use a catalog too:
```yaml
catalog:
typescript: ^5.9.0
```
```json
"devDependencies": { "typescript": "catalog:" }
```
Reference other packages of the workspace with `workspace:*`.
<!-- ‹guest · 2026-12-05› -->
3. **Use `peerDependencies` for packages that the host provides**, such as `eslint` for an ESLint plugin or `react` for a UI library.
4. **Approve build scripts one by one.** pnpm does not run the install scripts of dependencies unless they are listed in `allowBuilds`:
```yaml
allowBuilds:
lefthook: true
```
Check what a package's script does before you add it. Never approve an unknown package just because the install failed.
5. **Hoist only what tools must find.** pnpm does not expose the dependencies of your dependencies. For example, Prettier plugins need `publicHoistPattern` (see the `configuring-prettier` skill).
6. **Commit `pnpm-lock.yaml` with every change to a `package.json`**, and install with `--frozen-lockfile` in CI.
7. **Publish with `pnpm publish`**, never `npm publish`: pnpm replaces `catalog:` and `workspace:` with real versions.
## Verification
```bash
pnpm install --frozen-lockfile
```
It finishes without errors, and without changing `pnpm-lock.yaml`.
این نسخه با نشانهگذاری اختصاصی حساب شما نمایش داده میشود. برای نصب سریع، به تب نصب و راهاندازی بروید.