Skip to content
Latchkey

yarn add: Add Dependencies

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.

Key takeaways

  • -D for dev, -E to pin exact.
  • CI should not run yarn add.
  • Lockfile changes belong in PRs.

Related guides

Tired of flaky CI? Latchkey auto-heals failed jobs and retries them for you. Start free →