HerokuDanielle AdamsTutorial
Building a Monorepo with Yarn 2
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.
Source and freshness
- Source
- heroku.com
- Published
- Added to Yomu
Summaries are generated from the original by a language model. Check the original before relying on it.
Keep reading
Related reading
The Good Stuff
Paid picks we use ourselves. Links carry a referral code — a subscription through one earns us a commission at no extra cost to you.
The best engineering reads, once a week
One useful email. Unsubscribe anytime.