Resolution for Monorepos
What you'll learn: How TypeScript's module resolution handles workspace packages and local dependencies in monorepo setups.
The Monorepo Challenge
In a monorepo, you have multiple packages living side-by-side in a single repository. Package A might depend on Package B, but they're not published to npm — they're local workspace siblings. TypeScript needs to know how to find and type-check these internal dependencies without relying on node_modules.
Think of it like a campus directory system. Instead of looking up everyone in a global phone book, you have building-specific extensions that work differently from external numbers.
Workspace Protocol and Path Resolution
Modern package managers (npm workspaces, yarn, pnpm) use a workspace protocol to declare local dependencies:
{
"dependencies": {
"@myapp/shared": "workspace:*"
}
}
TypeScript doesn't natively understand workspace:*. Your package manager symlinks these into node_modules, but TypeScript's resolution follows those symlinks based on your moduleResolution setting.
Making It Work: baseUrl and paths
For direct source-to-source resolution (without going through node_modules), you configure paths:
{
"compilerOptions": {
"baseUrl": ".",
"paths": {
"@myapp/*": ["packages/*/src"]
}
}
}
Now when Package A imports @myapp/shared, TypeScript resolves it to packages/shared/src directly — no build step required.
Project References: The Right Way
TypeScript's Project References feature (covered in later lessons) is purpose-built for monorepos. Each package has its own tsconfig.json, and you declare dependencies between them. This enables incremental builds and proper type checking across package boundaries while respecting workspace structure.
Key Takeaway: Monorepo resolution requires either paths mappings for direct source access or relying on symlinked node_modules created by workspace-aware package managers — with Project References being the recommended long-term solution.