yarn(1)
Yarn is a fast, reliable, and secure dependency manager for JavaScript packages.
Synopsis
yarn [COMMAND] [OPTIONS]Description
Yarn is a package manager for JavaScript that works with npm and Node.js. It installs dependencies from package.json, manages versions, and provides a faster, more reliable alternative to npm with offline support and deterministic installs using yarn.lock.
Yarn uses a lockfile to ensure consistent installations across machines and developers. It features workspaces for monorepo support, parallel installation, and excellent error reporting with actionable messages.
Common options
| Flag | What it does |
|---|---|
install | Install all dependencies listed in package.json (default when no command given) |
add [PACKAGE] | Add a new package as a dependency; use --dev for devDependencies |
remove [PACKAGE] | Remove a package from dependencies |
--dev / -D | Save as a development dependency instead of production |
--global / -g | Install packages globally (available system-wide) |
--frozen-lockfile | Do not update yarn.lock; fail if it differs from package.json |
--offline | Use cached packages only; do not contact npm registry |
upgrade [PACKAGE] | Upgrade a package to its latest version within constraints |
why [PACKAGE] | Show which packages depend on the given package |
--verbose | Print more detailed output for debugging |
Examples
Install all dependencies from package.json and update yarn.lock
yarn installAdd lodash as a production dependency
yarn add lodashAdd jest as a development dependency
yarn add --dev jestRemove express package and update package.json
yarn remove expressUpgrade react to the latest available version
yarn upgrade react@latestInstall dependencies without modifying yarn.lock (useful in CI/CD)
yarn install --frozen-lockfileInstall create-react-app globally for use anywhere
yarn global add create-react-appShow which packages in the project depend on webpack
yarn why webpack