Skip to content
LatchkeyLatchkey home

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.

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.

Key takeaways

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

Frequently asked questions

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.

Related guides

References

Latchkey auto-heals failures like this one - detected, fixed, and retried without you. Start free → 30-day trial · No credit card