Yarn Package Manager Cheatsheet

Quick reference for Yarn: installation, dependency management, scripts, workspaces, cache, and CLI commands.

FeatureDescriptionExampleCategory
Install AllInstall all dependenciesyarn # or yarn installInstallation
Add PackageAdd new dependencyyarn add lodash yarn add react@17.0.2Installation
Add Dev DependencyAdd development dependencyyarn add -D jest yarn add --dev typescriptInstallation
Add Peer DependencyAdd peer dependencyyarn add -P reactInstallation
Add Optional DependencyAdd optional dependencyyarn add -O package-nameInstallation
Global InstallInstall package globallyyarn global add create-react-app yarn global add typescriptInstallation
Remove PackageRemove dependencyyarn remove lodash yarn remove react react-domDependencies
Upgrade PackageUpgrade specific packageyarn upgrade lodash yarn upgrade react@latestDependencies
Upgrade InteractiveInteractive upgrade promptyarn upgrade-interactive yarn upgrade-interactive --latestDependencies
Update LockfileRegenerate yarn.lockyarn install --force yarn install --frozen-lockfileDependencies
DeduplicateRemove duplicate dependenciesyarn dedupeDependencies
Run ScriptExecute package.json scriptyarn run build yarn run testScripts
Run ShorthandRun script without "run"yarn build yarn test yarn startScripts
Run with ArgsPass arguments to scriptsyarn test --watch yarn build --productionScripts
List ScriptsShow available scriptsyarn runScripts
List DependenciesShow dependency treeyarn list yarn list --depth=0Info
Show Package InfoDisplay package informationyarn info lodash yarn info react versionsInfo
Why PackageExplain why package is installedyarn why lodash yarn why webpackInfo
Check UpdatesCheck for outdated packagesyarn outdatedInfo
AuditCheck for security vulnerabilitiesyarn audit yarn audit --level moderateInfo
LicensesList package licensesyarn licenses listInfo
Workspace SetupDefine workspaces in package.json{ "workspaces": [ "packages/*", "apps/*" ] }Workspaces
Workspace CommandRun command in specific workspaceyarn workspace package-a add lodash yarn workspace my-app testWorkspaces
Workspace InfoShow workspace informationyarn workspaces infoWorkspaces
Run in All WorkspacesExecute in all workspacesyarn workspaces run test yarn workspaces run buildWorkspaces
Clean CacheClear Yarn cacheyarn cache clean yarn cache clean lodashCache
Cache DirectoryShow cache locationyarn cache dirCache
Cache ListList cached packagesyarn cache list yarn cache list --pattern lodashCache
Init ProjectInitialize new projectyarn init yarn init -yInstallation
Link PackageSymlink local packageyarn link yarn link package-nameDependencies
Unlink PackageRemove symlinked packageyarn unlink yarn unlink package-nameDependencies
VersionUpdate package versionyarn version --patch yarn version --minor yarn version --majorDependencies
PublishPublish package to registryyarn publish yarn publish --new-version 1.0.1Dependencies
Check IntegrityVerify package integrityyarn check yarn check --integrityInfo
ConfigManage Yarn configurationyarn config get registry yarn config set registry https://registry.npmjs.orgInfo