# npm vs Yarn

URL: https://softwaredictionary.org/compare/npm-vs-yarn
Last updated: 2026-10-06

In short: npm ships with Node.js and installs into `node_modules`; Yarn is a separate client for the same registry, with its own lockfile and Plug'n'Play installs.

## What is the difference between npm and Yarn?

npm and Yarn are both package managers for JavaScript: they read a project's `package.json`, download its dependencies from the same npm registry and lock their exact versions. npm is the default, created in 2010 and shipped with every installation of Node.js. Yarn was released by Facebook in 2016 as a faster, more predictable alternative, so it is a different client for the same packages, not a separate ecosystem.

Yarn's early lead came from ideas npm later adopted: a lockfile, `yarn.lock`, that pins every version, an offline cache and workspaces for several packages in one repository. npm added `package-lock.json` in 2017 and workspaces in 2020, so npm and Yarn Classic (version 1) now work much alike. The bigger difference today is modern Yarn, version 2 and later: its default Plug'n'Play mode skips `node_modules` and writes a single `.pnp.cjs` file that tells Node.js where each package sits in Yarn's cache, which makes installs lighter and makes undeclared imports fail.

Day to day, the commands are close: `yarn add react` for `npm install react`, and `yarn build` for `npm run build`, since Yarn doesn't need the word `run`. npm needs no setup, while modern Yarn is pinned per project in the `packageManager` field of `package.json` and usually set up with Corepack, which shipped with Node.js until version 25 and is now installed with `npm install -g corepack`. Tools that expect a real `node_modules` folder keep working under Yarn with `nodeLinker: node-modules` in `.yarnrc.yml`.

A common mistake is to mix the two in one project. Each writes its own lockfile, so installs drift apart; pick one, delete the other lockfile and record the choice in `packageManager`. Another misconception is that Yarn is always much faster: npm has closed much of the early gap, so the choice today is mostly about workflow, install layout and the monorepo tools a team prefers.

| Aspect | npm | Yarn |
| --- | --- | --- |
| Origin | Created in 2010; ships with Node.js | Released by Facebook in 2016; installed separately |
| Lockfile | `package-lock.json` | `yarn.lock` |
| Package layout | A `node_modules` folder with hoisted packages | Plug'n'Play by default in modern Yarn; `node_modules` optional |
| Running scripts | `npm run build`; only a few, such as `npm test`, skip `run` | `yarn build`; the word `run` is optional |
| One-off commands | `npx create-vite` | `yarn dlx create-vite` |
| Monorepos | Workspaces since 2020, with `--workspace` flags | Workspaces since 2017; modern Yarn adds `yarn workspaces foreach` |
| Setup | Nothing extra to install | Pinned in `packageManager`, set up with Corepack |
| Best for | The default path with no extra tooling | Teams that want Plug'n'Play, zero-installs or Yarn's monorepo tools |

## Choose npm when

- You want the default that ships with Node.js and needs no setup.
- Your hosting, CI images or tutorials assume `npm install` and `package-lock.json`.
- Your tools expect a regular `node_modules` folder.

## Choose Yarn when

- You want Plug'n'Play's strict dependency checks and lighter installs.
- You manage a monorepo and want commands such as `yarn workspaces foreach`.
- You want zero-installs: committing Yarn's cache so a fresh clone runs without installing.
- The project already uses Yarn and its `yarn.lock`.

## Frequently asked questions

**Is Yarn faster than npm?**

It was clearly faster when it appeared in 2016, and npm has closed much of that gap since. Modern Yarn with Plug'n'Play can still install large projects quicker because it writes far fewer files, but results depend on the project and the cache.

**Should I use Yarn Classic or modern Yarn?**

For new projects, modern Yarn: Yarn Classic (version 1) only gets occasional fixes. If Plug'n'Play causes problems with a tool, set `nodeLinker: node-modules` and keep the rest of modern Yarn.

**How do I switch a project from npm to Yarn?**

Set up Yarn with Corepack, delete `package-lock.json` and `node_modules`, then run `yarn` to resolve the dependencies from `package.json` and write `yarn.lock`. Commit the new lockfile and run the tests, since some versions may shift.

---

Software Dictionary: https://softwaredictionary.org/ · https://softwaredictionary.org/llms.txt
