← Back to Home

Yarn Cheat Sheet

Essential Yarn package manager commands

yarn init
Initialize a new package.json file. Use -y to accept all defaults quickly.

yarn init -y

Keywords: initialize, package, json, project, setup

yarn install
Install all dependencies from package.json. Creates yarn.lock file for consistent installs.

yarn install

Keywords: install, dependencies, modules, packages, lock

yarn add
Add a package to dependencies. Use --dev for development dependencies, --global for global installation.

yarn add express --dev

Keywords: add, install, package, dependency, dev

yarn remove
Remove a package from dependencies. Automatically updates package.json and yarn.lock.

yarn remove lodash

Keywords: remove, uninstall, package, dependency

yarn upgrade
Upgrade packages to their latest versions. Use --latest to ignore semver constraints.

yarn upgrade --latest

Keywords: upgrade, update, latest, version

yarn run
Execute scripts defined in package.json. List available scripts with yarn run without arguments.

yarn run build

Keywords: run, script, execute, build, start

yarn start
Run the start script defined in package.json. Shorthand for yarn run start.

yarn start

Keywords: start, run, server, application

yarn test
Run the test script defined in package.json. Shorthand for yarn run test.

yarn test

Keywords: test, testing, run, spec

yarn list
Display installed packages in tree format. Use --depth=0 for top-level only.

yarn list --depth=0

Keywords: list, installed, packages, tree, dependencies

yarn outdated
Check for outdated packages. Shows current and latest versions with color coding.

yarn outdated

Keywords: outdated, check, versions, update

yarn audit
Scan for security vulnerabilities in dependencies. Use --fix to automatically resolve issues.

yarn audit --fix

Keywords: audit, security, vulnerabilities, fix

yarn publish
Publish package to npm registry. Requires authentication and proper package.json configuration.

yarn publish

Keywords: publish, registry, package, release

yarn version
Bump package version. Use --patch, --minor, or --major for semantic versioning.

yarn version --patch

Keywords: version, bump, semver, patch, minor, major

yarn cache
Manage yarn cache. Use clean to clear cache, dir to show cache directory.

yarn cache clean

Keywords: cache, clean, clear, directory

yarn config
Manage yarn configuration. Set registry, proxy, or other yarn settings.

yarn config set registry https://registry.npmjs.org/

Keywords: config, configuration, registry, settings

yarn link
Create symbolic link for local development. Link packages for testing before publishing.

yarn link

Keywords: link, symbolic, local, development, testing

yarn info
Display detailed information about a package. Shows versions, dependencies, and metadata.

yarn info express

Keywords: info, information, package, details, metadata

yarn why
Explain why a package is installed. Shows dependency tree and reasons for installation.

yarn why lodash

Keywords: why, explain, dependency, tree, reason

yarn workspaces
Manage monorepo workspaces. Run commands across multiple packages in a workspace.

yarn workspaces run build

Keywords: workspaces, monorepo, multiple, packages

yarn dlx
Download and execute a package without installing it globally. Similar to npx.

yarn dlx create-react-app my-app

Keywords: dlx, execute, download, temporary, npx