mikexxz
All posts

pnpm, Bun, or npm: Choosing a Package Manager for a Monorepo

This post was machine-translated from Chinese. Read the original

This project is a monorepo: the frontend, the API, and a shared schema package live together. The original plan was a pnpm workspace, but I ended up switching to Bun.

Package Manager ≠ Runtime

Bun is three things at once: a package manager, a script runner, and a JavaScript runtime. You can choose them separately:

  • Package manager: Bun. Installs are fast, workspaces are supported natively, and the lockfile is in a text format
  • Runtime: still Node. Next.js primarily targets Node, so when something breaks it's easier to tell whose fault it is

The script that bun run dev executes calls next, and the shebang of next is #!/usr/bin/env node, so it actually runs on Node.

Isolated Installs

pnpm has one very important property: each package can only import the dependencies it has declared. Bun's isolated linker provides the same guarantee:

[install]
linker = "isolated"

Without this restriction, package A can happen to import package B's dependencies. Everything works locally, and you only discover the missing dependency declaration at deploy time.

Comments

Delete this comment?

Its content will be removed. This can’t be undone.