Yarn Overview
Yarn is a package manager for your code. It allows you to use and share code with other developers from around the world. Yarn does this quickly, securely, and reliably so you don't ever have to worry.
Key Features
- Speed: Parallel operations for maximum resource utilization
- Offline Mode: Work without internet connection
- Deterministic: Same dependencies on every install
- Network Resilience: Queue requests and retry if failures occur
- Flat Mode: Resolves mismatched versions of dependencies
- Workspaces: Manage multiple packages in one repository
- Plug'n'Play: Faster, lighter installation alternative
Installation & Setup
Installation Steps:
- Install Node.js (which includes npm) from official website
- Install Yarn globally via npm:
npm install -g yarn - Verify installation with:
yarn --version - Initialize a new project with:
yarn init - Start adding dependencies with:
yarn add [package]
Common Commands:
yarn install
Install all project dependencies
yarn add
Add a dependency to your project
yarn upgrade
Upgrade dependencies to their latest version
yarn workspace
Manage workspace packages
Productivity Tips
Selective Version Resolution
Force specific versions of transitive dependencies in package.json.
Workspaces
Use Yarn workspaces to manage monorepos with multiple packages.
Offline Mirror
Configure an offline mirror for CI/CD environments.
Plug'n'Play
Enable PnP for faster installs and smaller node_modules.