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- peerDependencyyarn add <pkg>@<tag>
Example
Add a dev tool pinned exactly.
shell
yarn add -D -E vitestIn CI
If CI runs yarn add, it will change the lockfile and break --immutable. Keep dependency changes in PRs, not the build.
Key takeaways
-Dfor dev,-Eto pin exact.- CI should not run
yarn add. - Lockfile changes belong in PRs.