How to Publish Monorepo Packages in Topological Order
Publishing dependencies before dependents means a consumer installing a dependent always finds the dependency version it declares.
If @acme/app requires @acme/core@^1.3.0, publishing app first would briefly point at a nonexistent core version. Tools sort the workspace graph topologically so leaves publish first.
How each tool orders
| Tool | Ordering behavior |
|---|---|
| changeset publish | Publishes in dependency order automatically |
| pnpm publish -r | Respects workspace topology |
| yarn foreach --topological | Explicit topological flag |
| nx release publish | Uses the Nx project graph |
Yarn example
Terminal
# Publish leaves first, dependents last
yarn workspaces foreach -A --no-private --topological npm publish --tolerate-republishGotchas
- A cyclic dependency between packages breaks topological ordering; keep the graph acyclic.
- Even with correct ordering, a mid-run failure can leave a partial release, so pair ordering with retry-safe (idempotent) publishing.
Related guides
How to Avoid Partial Releases in a MonorepoReduce the blast radius of a mid-publish failure by building all packages before publishing any, and by makin…
How to Bump Dependent Packages When a Dependency ChangesKeep internal package interdependencies correct by bumping dependents when a dependency releases, using the u…