Skip to main content
Sonamu projects are written in TypeScript, with API and Web each having independent tsconfig.json files. They use configurations optimized for their respective environments.

Project Structure

my-project/ - api/ - tsconfig.json # API server configuration - tsconfig.schemas.json # Schema generation - tsconfig.types.json # Type generation - web/ - tsconfig.json # React app configuration - tsconfig.node.json # Vite configuration
API and Web are independent TypeScript projects. Their configurations are separate.

API Server Configuration

Base tsconfig.json

api/tsconfig.json

Key Options Explained

moduleResolution: “bundler”
  • Uses bundler mode instead of Node.js’s node mode
  • Matches how Vite and esbuild resolve modules
  • Supports package.json’s exports field
Using moduleResolution: "node" may conflict with Vite.

Extended Configuration Files

Sonamu API uses additional tsconfig files for code generation.
api/tsconfig.schemas.json
Purpose:
  • Generate sonamu.generated.ts file
  • Generate Entity schema types
  • Convert DB schema → TypeScript types
When Used:The Sonamu CLI does not read this file directly. pnpm sonamu sync regenerates src/application/sonamu.generated.ts from the Entity and types files that changed since the last sync. The local dev server (pnpm sonamu dev) runs the same sync on startup and when watched files change.
api/tsconfig.types.json
Purpose:
  • Generate API response types
  • Define Request/Response types
  • Share types with frontend
When Used:The Sonamu CLI does not read this file directly. pnpm sonamu sync also copies changed *.types.ts files and the generated outputs to the configured sync targets such as Web.

Web (React) Configuration

web/tsconfig.json

Differences from API

API uses moduleResolution: "bundler" (lowercase), Web uses moduleResolution: "Bundler" (uppercase). Both make Vite resolve modules in bundler mode.

Path Mapping

You can import with absolute paths:
See Path Mapping for details.

Running Type Checks

During development, --watch mode is recommended for real-time type checking.

Common Troubleshooting

Symptoms:
Cause:
  • node_modules not installed
  • Incorrect import path
Solution:
Symptoms:
Cause:
  • experimentalDecorators is disabled
Solution:
Symptoms:
Cause:
  • jsx option not configured
Solution:
Required for React 17+
Symptoms:
Cause:
  • paths configuration missing
  • baseUrl configuration needed
Solution:
Vite configuration also needed:
vite.config.ts

Customization

Additional Library Types

Stricter Checks

These options may cause compatibility issues with existing code.

include/exclude Patterns

Next Steps

Type Checking

Learn about Strict mode and type check options

Path Mapping

Configure absolute path imports

Defining Entities

Define Entities

API Types

Define API request/response types