Convert Figma logo to code with AI

yarnpkg logoyarn

The 1.x line is frozen - features and bugfixes now happen on https://github.com/yarnpkg/berry

41,396
2,724
41,396
2,011

Top Related Projects

8,333

the package manager for JavaScript

29,125

Fast, disk space efficient package manager

Set up a modern web app by running one command.

64,559

A bundler for javascript and friends. Packs many modules into a few bundled assets. Code Splitting allows for loading parts of the application on demand. Through "loaders", modules can be CommonJs, AMD, ES6 modules, CSS, Images, JSON, Coffeescript, LESS, ... and your custom stuff.

78,700

Node Version Manager - POSIX-compliant bash script to manage multiple active node.js versions

10,872

Volta: JS Toolchains as Code. ⚡

Quick Overview

Yarn is a fast, reliable, and secure dependency management tool for JavaScript projects. It serves as an alternative to npm, offering improved performance, consistency, and offline capabilities. Yarn aims to solve common issues in the JavaScript ecosystem by providing a more robust and efficient package management experience.

Pros

  • Faster installation of packages compared to npm
  • Generates a yarn.lock file for consistent installations across different environments
  • Supports offline mode, allowing package installation without an internet connection
  • Improved security features, including checksum verification of packages

Cons

  • Learning curve for developers already familiar with npm
  • Some packages may have compatibility issues or be optimized for npm
  • Occasional conflicts with npm when used in the same project
  • Requires separate installation alongside Node.js (not bundled like npm)

Code Examples

  1. Installing a package:
yarn add lodash

This command adds the lodash package to your project and updates the package.json and yarn.lock files.

  1. Removing a package:
yarn remove express

This command removes the express package from your project and updates the package.json and yarn.lock files.

  1. Running a script defined in package.json:
yarn run start

This command executes the "start" script defined in your package.json file.

Getting Started

To get started with Yarn, follow these steps:

  1. Install Yarn globally:
npm install -g yarn
  1. Initialize a new project:
mkdir my-project
cd my-project
yarn init
  1. Add a dependency:
yarn add react
  1. Install all dependencies for an existing project:
yarn install

Now you're ready to use Yarn for managing your JavaScript project dependencies!

Competitor Comparisons

8,333

the package manager for JavaScript

Pros of npm

  • Larger ecosystem and wider adoption
  • Built-in to Node.js, no additional installation required
  • More frequent updates and active development

Cons of npm

  • Slower package installation compared to Yarn
  • Less deterministic package resolution
  • Higher disk space usage due to nested dependencies

Code Comparison

npm:

{
  "dependencies": {
    "express": "^4.17.1"
  }
}

Yarn:

dependencies:
  express: ^4.17.1

Both npm and Yarn use similar package.json structures, but Yarn introduces an additional yarn.lock file for deterministic installations. npm has since added package-lock.json for similar functionality.

npm focuses on simplicity and integration with Node.js, while Yarn emphasizes speed, security, and reliability. Yarn introduced features like offline mode and license checking, which npm later adopted.

Performance-wise, Yarn generally installs packages faster, especially on clean installs. However, npm has made significant improvements in recent versions.

Both package managers continue to evolve, with npm maintaining its position as the default choice for many developers, while Yarn offers an alternative with some unique features and optimizations.

29,125

Fast, disk space efficient package manager

Pros of pnpm

  • Efficient disk space usage through content-addressable storage
  • Faster installation times, especially for monorepos
  • Strict dependency resolution, preventing phantom dependencies

Cons of pnpm

  • Less widespread adoption compared to Yarn
  • Potential compatibility issues with some tools and workflows
  • Steeper learning curve for teams transitioning from npm or Yarn

Code Comparison

pnpm:

pnpm add react
pnpm run build
pnpm -r update

Yarn:

yarn add react
yarn build
yarn upgrade-interactive --latest

Key Differences

  • pnpm uses a unique symlink-based node_modules structure, while Yarn follows a more traditional flat structure
  • pnpm's content-addressable storage allows for significant disk space savings in large projects
  • Yarn has a larger ecosystem and more widespread adoption, particularly in established projects
  • pnpm offers better support for monorepos out of the box, while Yarn requires additional setup (e.g., Yarn Workspaces)

Both package managers aim to improve upon npm's shortcomings, but they take different approaches. pnpm focuses on efficiency and strict dependency management, while Yarn emphasizes speed and reliability. The choice between the two often depends on specific project requirements and team preferences.

Set up a modern web app by running one command.

Pros of Create React App

  • Provides a complete, pre-configured React development environment
  • Simplifies the process of starting a new React project with best practices
  • Includes built-in testing setup and production build optimization

Cons of Create React App

  • Less flexible for customizing build configurations
  • Larger initial project size due to included dependencies
  • May include unnecessary features for simpler projects

Code Comparison

Create React App:

import React from 'react';
import ReactDOM from 'react-dom';
import App from './App';

ReactDOM.render(<App />, document.getElementById('root'));

Yarn:

const yarn = require('yarn');

yarn.install()
  .then(() => console.log('Packages installed successfully'))
  .catch(error => console.error('Installation failed:', error));

Key Differences

  • Purpose: Create React App is focused on React application development, while Yarn is a general-purpose package manager
  • Scope: Create React App provides a complete development environment, whereas Yarn manages dependencies for various projects
  • Usage: Create React App is typically used to start new React projects, while Yarn is used throughout development for package management

Similarities

  • Both tools aim to improve developer experience and productivity
  • Both are widely used in the JavaScript ecosystem
  • Both have active communities and regular updates
64,559

A bundler for javascript and friends. Packs many modules into a few bundled assets. Code Splitting allows for loading parts of the application on demand. Through "loaders", modules can be CommonJs, AMD, ES6 modules, CSS, Images, JSON, Coffeescript, LESS, ... and your custom stuff.

Pros of webpack

  • More comprehensive build tool, handling bundling, minification, and asset management
  • Highly configurable with a rich ecosystem of plugins and loaders
  • Better suited for complex JavaScript applications and Single Page Apps (SPAs)

Cons of webpack

  • Steeper learning curve and more complex configuration
  • Can be overkill for simpler projects or libraries
  • Slower build times for large projects compared to Yarn's package management

Code Comparison

webpack configuration example:

module.exports = {
  entry: './src/index.js',
  output: {
    filename: 'bundle.js',
    path: path.resolve(__dirname, 'dist')
  },
  module: {
    rules: [
      { test: /\.js$/, use: 'babel-loader' }
    ]
  }
};

Yarn usage example:

yarn add package-name
yarn run build
yarn test

Summary

webpack is a powerful build tool focused on bundling and asset management, while Yarn is primarily a package manager. webpack offers more advanced features for complex applications but requires more setup. Yarn provides simpler package management and faster installation times. The choice between them depends on project requirements and complexity.

78,700

Node Version Manager - POSIX-compliant bash script to manage multiple active node.js versions

Pros of nvm

  • Allows easy switching between Node.js versions
  • Supports multiple shells (bash, zsh, fish)
  • Lightweight and focused on Node.js version management

Cons of nvm

  • Limited to Node.js ecosystem, unlike Yarn's broader package management
  • Requires manual installation of npm for each Node version
  • Less robust dependency resolution compared to Yarn

Code Comparison

nvm:

nvm install 14.17.0
nvm use 14.17.0
node -v

Yarn:

yarn add package-name
yarn install
yarn run start

Key Differences

  • Purpose: nvm manages Node.js versions, while Yarn manages package dependencies
  • Scope: nvm is Node.js-specific, Yarn works with multiple JavaScript environments
  • Features: Yarn offers advanced package management, while nvm focuses on version switching
  • Performance: Yarn generally provides faster package installations than npm (which is used with nvm)

Use Cases

  • Use nvm when you need to switch between Node.js versions frequently
  • Choose Yarn for efficient package management and dependency resolution in JavaScript projects

Both tools serve different purposes in the JavaScript ecosystem, with nvm focusing on Node.js version management and Yarn on package management and dependency resolution.

10,872

Volta: JS Toolchains as Code. ⚡

Pros of Volta

  • Manages multiple Node.js versions and tools across projects
  • Seamless integration with project-specific configurations
  • Faster installation and switching between Node.js versions

Cons of Volta

  • Limited to Node.js ecosystem, unlike Yarn's broader package management
  • Smaller community and ecosystem compared to Yarn
  • Less extensive documentation and resources available

Code Comparison

Volta (project configuration):

{
  "node": "14.15.0",
  "yarn": "1.22.10"
}

Yarn (package.json):

{
  "engines": {
    "node": ">=14.15.0",
    "yarn": "^1.22.0"
  }
}

Volta focuses on managing Node.js versions and tools, while Yarn primarily handles package management. Volta's configuration is more concise and directly specifies the exact versions to use, whereas Yarn's approach allows for more flexible version ranges within the package.json file.

Volta excels in providing a consistent development environment across team members and CI/CD pipelines, ensuring everyone uses the same Node.js and tool versions. Yarn, on the other hand, offers a more comprehensive package management solution with features like workspaces and plug'n'play.

Both tools have their strengths, and the choice between them depends on specific project requirements and team preferences.

Convert Figma logo designs to code with AI

Visual Copilot

Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.

Try Visual Copilot

README

ℹ️ Important note

This repository holds the sources for Yarn 1.x (latest version at the time of this writing being 1.22). New releases (at this time the 3.2.3, although we're currently working on our next major) are tracked on the yarnpkg/berry repository, this one here being mostly kept for historical purposes and the occasional hotfix we publish to make the migration from 1.x to later releases easier.

If you hit bugs or issues with Yarn 1.x, we strongly suggest you migrate to the latest release - at this point they have been maintained longer than 1.x, and many classes of problems have already been addressed there. By using the nodeLinker setting you'll also have the choice of how you want to install your packages: node_modules like npm, symlinks like pnpm, or manifest files via Yarn PnP.


Fast, reliable, and secure dependency management.

Circle Status Appveyor Status Azure Pipelines status Discord Chat Commitizen friendly


Fast: Yarn caches every package it has downloaded, so it never needs to download the same package again. It also does almost everything concurrently to maximize resource utilization. This means even faster installs.

Reliable: Using a detailed but concise lockfile format and a deterministic algorithm for install operations, Yarn is able to guarantee that any installation that works on one system will work exactly the same on another system.

Secure: Yarn uses checksums to verify the integrity of every installed package before its code is executed.

Features

  • Offline Mode. If you've installed a package before, then you can install it again without an internet connection.
  • Deterministic. The same dependencies will be installed in the same exact way on any machine, regardless of installation order.
  • Network Performance. Yarn efficiently queues requests and avoids request waterfalls in order to maximize network utilization.
  • Network Resilience. A single request that fails will not cause the entire installation to fail. Requests are automatically retried upon failure.
  • Flat Mode. Yarn resolves mismatched versions of dependencies to a single version to avoid creating duplicates.
  • More emojis. 🐈

Our supports

Gold sponsors

All your environment variables, in one place. Stop struggling with scattered API keys, hacking together home-brewed tools, and avoiding access controls. Keep your team and servers in sync with Doppler.
Your app, enterprise-ready. Start selling to enterprise customers with just a few lines of code. Add Single Sign-On (and more) in minutes instead of months with WorkOS.

Installing Yarn

Read the Installation Guide on our website for detailed instructions on how to install Yarn.

Using Yarn

Read the Usage Guide on our website for detailed instructions on how to use Yarn.

Contributing to Yarn

The 1.x codebase is fairly old and will only accept security fixes. For new features or bugfixes, please see our new repository and its contribution guide.

Prior art

Yarn wouldn't exist if it wasn't for excellent prior art. Yarn has been inspired by the following projects:

Credits

Thanks to Sam Holmes for donating the npm package name!

NPM DownloadsLast 30 Days