# yarn add: Add Dependencies

> yarn add installs and records a dependency. Learn dev, exact, and peer flags, and why CI rarely runs it.

Source: https://latchkey.dev/learn/command-reference/yarn-add-command-reference  
Updated: 2026-06-26

yarn add installs a package and writes it to package.json.

yarn add is a developer command; CI normally only installs from the committed lockfile.

## Common flags

- `-D` / `--dev` - devDependency
- `-E` / `--exact` - pin exact version
- `-P` / `--peer` - peerDependency
- `yarn add <pkg>@<tag>`

## Example

Add a dev tool pinned exactly.

```shell
yarn add -D -E vitest
```

## In CI

If CI runs `yarn add`, it will change the lockfile and break `--immutable`. Keep dependency changes in PRs, not the build.

## Using this in CI

Node tooling on a runner differs from your machine in three ways that matter: `CI=true` is set, there is no TTY, and the Node major may not be the one you develop on.

- Pin the Node major with `setup-node` and in `engines`. Native modules resolve different prebuilt binaries per major.
- `CI=true` changes behaviour in several tools, most often by promoting warnings to errors or disabling interactive prompts.
- Commands that expect a TTY will hang. Pass the non-interactive or `--yes` flag explicitly.
- Use `npm exec` or `node_modules/.bin` rather than assuming a globally installed binary is on PATH.

## FAQ

### yarn add: Add Dependencies?

yarn add is a developer command; CI normally only installs from the committed lockfile.

### Example?

Add a dev tool pinned exactly.

### In CI?

If CI runs yarn add, it will change the lockfile and break --immutable. Keep dependency changes in PRs, not the build.

---

Latchkey runs CI/CD that repairs its own failures. Agent entry points: https://latchkey.dev/agent.txt, https://latchkey.dev/openapi.json, https://latchkey.dev/llms.txt
