---
title: "Building a Monorepo with Yarn 2"
description: "The post presents Yarn 2 workspaces as a way to manage dependencies for a JavaScript or Node.js monorepo containing separate server and UI applications. It configures the root package.json with workspace directories, imports the workspace-tools plugin, pins the project to a checked-in Yarn binary with yarn set version berry, and enables the dependency cache through .yarn/cache and Plug’n’Play. The walkthrough adds Express, TypeScript, and @types/express to a server workspace, creates a Next.js UI workspace, and uses workspace scripts to build both applications, while yarn dlx initializes TypeScript without a global install. It also shows the Git files to retain, generated JavaScript to ignore, and a Heroku start script that launches the server workspace; the stated benefit is faster installs through a committed cache and zero-install deployment."
---

# Building a Monorepo with Yarn 2

[Heroku](https://yomu.fyi/company/heroku) · Danielle Adams · Dec 23, 2020

**Type:** Tutorial

## Summary

The post presents Yarn 2 workspaces as a way to manage dependencies for a JavaScript or Node.js monorepo containing separate server and UI applications. It configures the root package.json with workspace directories, imports the workspace-tools plugin, pins the project to a checked-in Yarn binary with yarn set version berry, and enables the dependency cache through .yarn/cache and Plug’n’Play. The walkthrough adds Express, TypeScript, and @types/express to a server workspace, creates a Next.js UI workspace, and uses workspace scripts to build both applications, while yarn dlx initializes TypeScript without a global install. It also shows the Git files to retain, generated JavaScript to ignore, and a Heroku start script that launches the server workspace; the stated benefit is faster installs through a committed cache and zero-install deployment.

## Context

The post addresses dependency management and build coordination for a JavaScript or Node.js monorepo with separate server and UI workspaces. It also covers version consistency between development environments, dependency caching, and deployment on Heroku.

## Approach / What changed

It sets up Yarn 2 with a checked-in binary, configures workspaces and the workspace-tools plugin, enables Plug’n’Play and the committed dependency cache, adds dependencies to individual workspaces, defines build and start scripts, and configures Heroku to launch the server workspace.

## Takeaways

- The root package.json lists the server and ui directories under workspaces, while the workspace-tools plugin enables commands such as yarn workspaces foreach run build.
- Yarn 2 creates .pnp.js, .yarn/cache, and yarn.lock; .pnp.js tells the Node app or build how to locate dependencies stored in the cache.
- Heroku uses the root package.json start script to start the web process, with the example delegating startup to the server workspace.

**Tags:** [Heroku](https://yomu.fyi/topic/heroku), [JavaScript](https://yomu.fyi/topic/javascript), [Node.js](https://yomu.fyi/topic/node-js), [Yarn](https://yomu.fyi/topic/yarn)

- Source: [Heroku](https://www.heroku.com/blog/building-a-monorepo-with-yarn-2)
- Source URL: https://www.heroku.com/blog/building-a-monorepo-with-yarn-2
- Ingested by Yomu: 2026-09-09T20:03:05.266Z

[Read original post](https://www.heroku.com/blog/building-a-monorepo-with-yarn-2)
