Package Installation

A package manager (like npm) handles two things for you: managing workspaces and installing packages.

Turborepo is compatible with four package managers:

You should use whichever you feel most comfortable with - but if you're a monorepo beginner, we recommend npm.

If you're comfortable with monorepos, we recommend pnpm. It's faster and offers some useful CLI options like --filter.

Installing packages

When you first clone or create your monorepo, you'll need to:

  1. Make sure you're in the root directory of your monorepo
  2. Run the install command:
npm install
yarn install
pnpm install

You'll now see node_modules folders appear in the root of your repository, and in each workspace.

Adding/removing/upgrading packages

You can add, remove and upgrade packages from within your monorepo using your package manager's built-in commands:

Install a package in a workspace

npm install <package> --workspace=<workspace>

Example:

npm install react --workspace=web

Remove a package from a workspace

npm uninstall <package> --workspace=<workspace>

Example:

npm uninstall react --workspace=web

Upgrade a package in a workspace

npm update <package> --workspace=<workspace>

Example:

npm update react --workspace=web

Install a package in a workspace

yarn workspace <workspace> add <package>

Example:

yarn workspace web add react

Remove a package from a workspace

yarn workspace <workspace> remove <package>

Example:

yarn workspace web remove react

Upgrade a package in a workspace

yarn workspace <workspace> upgrade <package>

Example:

yarn workspace web upgrade react

Install a package in a workspace

pnpm add <package> --filter <workspace>

Example:

pnpm add react --filter web

Remove a package from a workspace

pnpm uninstall <package> --filter <workspace>

Example:

pnpm uninstall react --filter web

Upgrade a package in a workspace

pnpm update <package> --filter <workspace>

Example:

pnpm update react --filter web
Last updated on September 20, 2022