Skip to content
Latchkey

pnpm add: Usage, Options & Common Errors

Add a dependency to a package or the workspace root.

pnpm add installs packages and records them in package.json, updating pnpm-lock.yaml - with workspace-aware flags for monorepos.

What it does

Resolves and links the requested packages and saves them to dependencies (or devDependencies with -D). -w adds to the workspace root manifest; --filter <pkg> targets a specific workspace package. Use -E for an exact version.

Common usage

Terminal
pnpm add lodash             # runtime dependency
pnpm add -D typescript      # devDependency
pnpm add -w prettier        # add to the workspace root
pnpm add --filter @acme/web react

Common CI error: ERR_PNPM_FETCH_404

pnpm add fails with "ERR_PNPM_FETCH_404 / GET ... 404 Not Found". The package name is wrong, or it is private and the registry/auth is not configured. Verify the name, and set the registry and auth token (.npmrc) for private scopes before adding.

.npmrc
# private scope auth in .npmrc:
//registry.acme.dev/:_authToken=${NPM_TOKEN}
@acme:registry=https://registry.acme.dev/

Related guides

Run this faster and cheaper on Latchkey managed runners. Start free →