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.
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.
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-nodeand inengines. Native modules resolve different prebuilt binaries per major. CI=truechanges 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
--yesflag explicitly. - Use
npm execornode_modules/.binrather than assuming a globally installed binary is on PATH.
Key takeaways
-Dfor dev,-Eto pin exact.- CI should not run
yarn add. - Lockfile changes belong in PRs.