DEV Community

arenasbob2024-cell
arenasbob2024-cell

Posted on • Originally published at viadreams.cc

Monorepo in 2026: Turborepo vs Nx vs pnpm Workspaces

Managing multiple related packages is painful. Monorepos solve it by putting everything in one repo with shared tooling.

Why Monorepos?

  • Atomic commits across multiple packages
  • Shared code without npm publishing dance
  • Consistent tooling (ESLint, TypeScript, tests) everywhere
  • Easy refactoring across package boundaries

pnpm Workspaces (The Foundation)

Most monorepo tools build on workspace protocols. pnpm's is the best:

# pnpm-workspace.yaml
packages:
  - 'apps/*'
  - 'packages/*'
Enter fullscreen mode Exit fullscreen mode
// packages/ui/package.json
{ "name": "@myapp/ui", "version": "1.0.0" }

// apps/web/package.json
{
  "dependencies": {
    "@myapp/ui": "workspace:*"  // Always uses local version
  }
}
Enter fullscreen mode Exit fullscreen mode
pnpm install           # Install all packages
pnpm -r build          # Build all packages
pnpm -F @myapp/ui dev  # Run dev in specific package
Enter fullscreen mode Exit fullscreen mode

Turborepo: Speed First

Turborepo's killer feature is remote caching — build once, share across your team:

// turbo.json
{
  "pipeline": {
    "build": {
      "dependsOn": ["^build"],   // Build deps first
      "outputs": [".next/**", "dist/**"]
    },
    "test": {
      "dependsOn": ["build"],
      "outputs": []
    },
    "lint": {
      "outputs": []
    }
  }
}
Enter fullscreen mode Exit fullscreen mode
turbo run build         # Builds in optimal order, caches results
turbo run build --dry   # Show what would run
turbo run build --graph # Visualize the dependency graph
Enter fullscreen mode Exit fullscreen mode

Remote Caching

turbo login              # Connect to Vercel (free for personal use)
turbo link               # Link this repo

# Now: if CI built this exact code, turbo downloads the cache
# instead of rebuilding. Zero time builds on unchanged packages.
Enter fullscreen mode Exit fullscreen mode

Nx: Full-Featured Monorepo Framework

Nx goes further with code generation, dependency graph visualization, and affected commands:

npx create-nx-workspace myapp --preset=next

# Generate components/apps
nx g @nx/react:component Button --project=ui
nx g @nx/next:app dashboard

# Only run tasks affected by changes
nx affected --target=build
nx affected --target=test --base=main

# Visualize the entire dependency graph
nx graph
Enter fullscreen mode Exit fullscreen mode

Nx can also enforce module boundaries:

// .eslintrc.json
{
  "rules": {
    "@nx/enforce-module-boundaries": ["error", {
      "depConstraints": [
        { "sourceTag": "scope:app", "onlyDependOnLibsWithTags": ["scope:lib"] },
        { "sourceTag": "type:ui", "onlyDependOnLibsWithTags": ["type:ui", "type:util"] }
      ]
    }]
  }
}
Enter fullscreen mode Exit fullscreen mode

Choosing

pnpm workspaces Turborepo Nx
Setup Simple Easy More setup
Caching No Yes (Vercel) Yes (Nx Cloud)
Code gen No No Yes
Best for Small teams Medium projects Large orgs
Opinionated No Low High

Recommendation: Start with pnpm workspaces. Add Turborepo when builds get slow. Switch to Nx if you need code generation and enforcement.

Use JSON Validator to validate your workspace configuration files.


Full monorepo guide at viadreams.cc/en/blog/monorepo-tools-2026

Top comments (0)