Agent skill
typescript-monorepo-builds
Configure TypeScript for the Orient monorepo packages. Use when creating new packages, fixing build errors, configuring tsconfig.json, setting up project references, or debugging "cannot find module" errors. Covers package tsconfig templates, turbo build order, path aliases, and common build errors.
Install this agent skill to your Project
npx add-skill https://github.com/majiayu000/claude-skill-registry/tree/main/skills/data/typescript-monorepo-builds
SKILL.md
TypeScript Monorepo Builds
Quick Reference
# Build all packages (respects dependency order)
pnpm turbo build
# Build specific package and its dependencies
pnpm --filter @orientbot/package-name... build
# Type check without building
pnpm turbo typecheck
# Clean all build artifacts
pnpm turbo clean
Package tsconfig.json Template
Every package in packages/ should have this configuration:
{
"compilerOptions": {
"target": "ES2022",
"module": "NodeNext",
"moduleResolution": "NodeNext",
"lib": ["ES2022"],
"outDir": "./dist",
"rootDir": "./src",
"declaration": true,
"declarationMap": true,
"sourceMap": true,
"strict": true,
"esModuleInterop": true,
"skipLibCheck": true,
"forceConsistentCasingInFileNames": true,
"resolveJsonModule": true,
"isolatedModules": true
},
"include": ["src/**/*.ts"],
"exclude": ["node_modules", "dist", "__tests__"]
}
Key Options Explained
| Option | Value | Purpose |
|---|---|---|
module |
NodeNext |
ESM-compatible module system |
moduleResolution |
NodeNext |
Matches Node.js module resolution |
declaration |
true |
Generate .d.ts type files |
declarationMap |
true |
Enable Go-to-Definition for consumers |
isolatedModules |
true |
Required for esbuild/swc compatibility |
Project References (For Cross-Package Imports)
When a package imports from another package at compile time, add project references:
{
"compilerOptions": {
"composite": true
},
"references": [{ "path": "../core" }, { "path": "../database" }]
}
Note: Project references require composite: true in the referenced package's tsconfig.
When to Use References
- ✅ Package directly imports types from another package
- ✅ Package uses workspace dependency (
"@orientbot/core": "workspace:*") - ❌ Package only uses runtime exports (no compile-time dependency)
Build Order with Turbo
Turbo automatically builds dependencies first via dependsOn: ["^build"]:
// turbo.json
{
"tasks": {
"build": {
"dependsOn": ["^build"],
"outputs": ["dist/**"]
}
}
}
Build Order
1. @orientbot/core (no dependencies)
2. @orientbot/database (depends on core)
3. @orientbot/database-services (depends on database)
4. @orientbot/integrations (depends on core, database)
5. @orientbot/agents (depends on database-services)
6. @orientbot/mcp-tools (depends on agents, integrations)
7. @orientbot/bot-* (depends on mcp-tools, agents)
Root tsconfig.json Path Aliases
The root tsconfig.json defines path aliases for development:
{
"compilerOptions": {
"baseUrl": ".",
"paths": {
"@orientbot/core": ["./packages/core/src/index"],
"@orientbot/database": ["./packages/database/src/index"],
"@orientbot/agents": ["./packages/agents/src/index"]
}
}
}
Important: Path aliases point to source files for development, but production builds use dist via package.json exports.
Incremental Compilation Troubleshooting
Stale .tsbuildinfo Files
Symptom: Build completes with no errors but dist/ is empty. Turbo shows "cache hit" or warns "no output files found."
Cause: .tsbuildinfo stores incremental state. When stale, tsc skips compilation entirely.
Fix:
find packages -name "*.tsbuildinfo" -delete
rm -f .tsbuildinfo
pnpm run build:packages
Verifying Build Completion
Always verify dist/ before running dependent builds or tests:
# After build, verify all packages have dist/index.js
ls packages/*/dist/index.js
# If any are missing, that package didn't compile
# Check for stale tsbuildinfo or stray .js files in src/
Empty dist/ Despite "Cache Hit"
Turbo's cache can be misleading when tsbuildinfo is stale:
- Turbo checks its cache → finds cached task
- Replays cached tsc (which produced no output due to stale tsbuildinfo)
- Result: "cache hit" but empty dist/
Fix: Clean both turbo cache AND tsbuildinfo:
rm -rf .turbo packages/*/.turbo
find packages -name "*.tsbuildinfo" -delete
pnpm run build:packages
Common Build Errors
"Cannot find module '@orientbot/package'" (TS2307)
Most common cause: Prerequisite package didn't build (empty dist/).
- Verify prerequisite dist exists:
ls packages/package/dist/index.js - If empty, clean tsbuildinfo and rebuild:
find packages -name "*.tsbuildinfo" -delete && pnpm run build:packages - If still failing, check package.json exports match dist structure
"Type 'X' is not assignable to type 'Y'"
Cross-package type mismatches usually mean:
- Stale build: Run
pnpm turbo build --force - Different TypeScript versions: Check
peerDependencies - Missing type export: Add to package's
index.ts
"Cannot find name 'X'" in tests
Tests don't use project references. Add vitest path aliases:
// vitest.config.ts
export default defineConfig({
resolve: {
alias: {
'@orientbot/core': resolve(__dirname, '../core/src'),
},
},
});
"Declaration emit skipped"
error TS5069: Option 'declarationDir' cannot be specified
Ensure outDir is set and remove declarationDir:
{
"compilerOptions": {
"outDir": "./dist",
"declaration": true
}
}
Circular Reference Error
error TS6202: Project references may not form a circular graph
Check references in tsconfig files. Package A cannot reference B if B references A.
Creating a New Package
-
Create package structure:
bashmkdir -p packages/new-package/src -
Create
package.json:json{ "name": "@orientbot/new-package", "version": "1.0.0", "type": "module", "main": "./dist/index.js", "types": "./dist/index.d.ts", "exports": { ".": { "types": "./dist/index.d.ts", "import": "./dist/index.js" } }, "scripts": { "build": "tsc", "typecheck": "tsc --noEmit" } } -
Create
tsconfig.jsonusing the template above -
Add workspace dependency to consumers:
json{ "dependencies": { "@orientbot/new-package": "workspace:*" } } -
Add path alias to root
tsconfig.json -
Build:
pnpm --filter @orientbot/new-package build
Debugging Build Issues
# Verbose TypeScript output
pnpm --filter @orientbot/package tsc --listFiles
# Check what files are included
pnpm --filter @orientbot/package tsc --listFilesOnly
# Trace module resolution
pnpm --filter @orientbot/package tsc --traceResolution
# Show build dependency graph
pnpm turbo build --graph
# Force rebuild ignoring cache
pnpm turbo build --force
Best Practices
- Keep packages focused - smaller packages = faster builds
- Use
composite: trueonly when needed for references - Build before testing -
dependsOn: ["^build"]in turbo.json - Export types explicitly -
export type { X }in barrel files - Match exports to dist - package.json exports must match dist structure
Didn't find tool you were looking for?