Skip to content
Latchkey

yarn add: Usage, Options & Common Errors

Add a dependency and update package.json.

yarn add installs one or more packages and records them in package.json, updating yarn.lock - the yarn equivalent of npm install <pkg>.

What it does

Resolves and installs the requested packages, adds them to dependencies (or devDependencies with -D), and updates yarn.lock. -E pins an exact version instead of a caret range.

Common usage

Terminal
yarn add lodash             # runtime dependency
yarn add -D typescript      # devDependency
yarn add react@18           # specific version
yarn add -E zod             # pin exact version

Common CI error: couldn’t find package

yarn add fails with "Couldn’t find package \"x\" on the \"npm\" registry". The name is misspelled, the package is private and needs auth, or the registry is wrong. Verify the exact name, and configure registry auth (.npmrc / .yarnrc.yml) for private scopes before installing.

Terminal
# private scope needs auth in .yarnrc.yml (Berry):
yarn config set npmScopes.acme.npmAuthToken ${NPM_TOKEN}

Related guides

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