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 versionCommon 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
yarn "Couldn't find package … required by …" - Fix Resolution in CIFix yarn "Couldn't find package X required by Y" in CI - a dependency or version that yarn cannot resolve fro…
yarn "Couldn't find any versions for <pkg> that match <range>" - Fix in CIFix yarn "Couldn't find any versions for <pkg> that matches <range>" in CI - a version range no published rel…
yarn install: Usage, Options & Common CI Errorsyarn install resolves and installs dependencies from yarn.lock. Usage, the --immutable / --frozen-lockfile CI…