Skip to main content
The Sentry JavaScript SDK uses a monorepo structure to manage 40+ packages efficiently. This guide explains how the monorepo is organized and how the build system works.

Workspace Management

Yarn Workspaces

The monorepo uses Yarn Workspaces for dependency management. All workspaces are defined in the root package.json:
Yarn Workspaces provides:
  • Shared dependencies - Common dependencies are hoisted to the root node_modules
  • Symlinked packages - Internal packages are symlinked for local development
  • Single lock file - All dependencies managed in one yarn.lock

Installing Dependencies

Run yarn from the root to install all dependencies for all packages:
This:
  1. Installs all dependencies listed in every package.json
  2. Hoists shared dependencies to the root
  3. Symlinks internal packages together

Directory Structure

Build Orchestration with Nx

The monorepo uses Nx for build orchestration, caching, and affected analysis.

Why Nx?

  • Task orchestration - Runs tasks across packages in the correct order
  • Intelligent caching - Caches build outputs to speed up rebuilds
  • Affected detection - Runs tasks only for packages affected by changes
  • Parallel execution - Runs independent tasks in parallel

Nx Configuration

Nx is configured in nx.json:
Key features:
  • dependsOn - Defines task dependencies
  • ^ prefix - Means “this target’s dependencies from upstream packages”
  • outputs - Tells Nx what files to cache
  • cache: true - Enables caching for the target
  • parallel: 5 - Runs up to 5 tasks in parallel

Running Tasks with Nx

Nx provides several ways to run tasks:
These are wrapped in convenient yarn scripts:

Package Structure

Each package follows a consistent structure:

Package Entry Points

Packages use exports to define entry points:
This configuration:
  • Supports both CommonJS and ES modules
  • Provides TypeScript types
  • Offers downleveled types for older TypeScript versions

Dependency Management

Internal Dependencies

Packages depend on each other via workspace protocol:
During publishing, workspace:* is replaced with the actual version.

Shared Dependencies

Common development dependencies are defined in the root package.json:

Dependency Resolutions

Forced dependency versions are specified in resolutions:

Build Outputs

After building, each package contains:

CommonJS (CJS)

For Node.js and bundlers that prefer CommonJS.

ES Modules (ESM)

For modern bundlers and native ES module support.

TypeScript Types

CDN Bundles (Browser Only)

Nx Cache

Nx caches build outputs in .nxcache/:
Caching speeds up rebuilds significantly. Clear it with:

Version Management with Volta

Volta ensures everyone uses the same tool versions:
Packages inherit from the root:

Scripts Organization

Root scripts coordinate across all packages:
  • run-s - Run scripts sequentially
  • run-p - Run scripts in parallel
  • nx run-many - Run tasks across packages

Next Steps