Careeroza
isolatedModules and Project References
isolatedModules
Fast tools (esbuild, SWC, Babel, Vite, Next.js, tsx) compile one file at a time and only strip types. "isolatedModules": true makes TypeScript warn about code that needs information from other files to compile correctly:
- re-exporting a type without
export type(export { Product } from "./types"), - using
const enumdeclared in another file, - files that are not modules (no import/export).
// with isolatedModules / verbatimModuleSyntax
export type { Product } from "./types"; // correct
export { formatInr } from "./format"; // values are fineProject References (Monorepos)
Large repositories split code into several TypeScript projects that build in order. Each referenced project needs "composite": true; tsc --build (tsc -b) only rebuilds what changed.
shopease/
tsconfig.json { "files": [], "references": [{ "path": "packages/shared" },
{ "path": "apps/api" }, { "path": "apps/web" }] }
packages/shared/tsconfig.json { "compilerOptions": { "composite": true, "outDir": "dist" } }
apps/api/tsconfig.json { "references": [{ "path": "../../packages/shared" }] }
apps/web/tsconfig.json { "references": [{ "path": "../../packages/shared" }] }Example
npx tsc -b # build everything in dependency order
npx tsc -b --watch # incremental rebuildsNote: In npm/pnpm workspaces with Turborepo or Nx, many teams use plain workspace packages instead of project references. Both are common.