TypeScript Alias Path Replacer

1.8.16 · active · verified Sun Apr 19

tsc-alias is a utility designed to resolve TypeScript's `paths` aliases into relative paths *after* TypeScript compilation has completed. This ensures that the compiled JavaScript files can be run directly without requiring additional runtime modules like `tsconfig-paths`, distinguishing it through its compile-time-only approach. The package is currently at version `1.8.16` (as of May 2025) and maintains an active release cadence with frequent patches addressing compatibility and bug fixes. It is typically integrated into `package.json` build scripts alongside `tsc`, providing a robust solution for managing complex module import structures in both Node.js and browser environments. It ships with TypeScript types and requires Node.js `^16.20.2` or later.

Common errors

Warnings

Install

Imports

Quickstart

Demonstrates how to configure and run `tsc-alias` with TypeScript aliases in a build script.

{
  "name": "tsc-alias-example",
  "version": "1.0.0",
  "main": "dist/index.js",
  "scripts": {
    "build": "tsc --project tsconfig.json && tsc-alias -p tsconfig.json",
    "start": "npm run build && node dist/index.js"
  },
  "devDependencies": {
    "typescript": "^5.0.0",
    "tsc-alias": "^1.8.16"
  }
}
// Save as package.json

// ------------------------------------------------------------------

{
  "compilerOptions": {
    "target": "es2020",
    "module": "commonjs",
    "outDir": "./dist",
    "baseUrl": "./src",
    "paths": {
      "@utils/*": ["utils/*"],
      "@config": ["config.ts"]
    },
    "esModuleInterop": true,
    "forceConsistentCasingInFileNames": true,
    "strict": true,
    "skipLibCheck": true
  },
  "include": ["src/**/*.ts", "src/**/*.json"]
}
// Save as tsconfig.json

// ------------------------------------------------------------------

// src/config.ts
export const appName = "My Tsc-Alias App";

// src/utils/helper.ts
export const greet = (name: string) => `Hello, ${name}!`;

// src/index.ts
import { greet } from '@utils/helper'; // Using an alias
import { appName } from '@config';     // Another alias

console.log(`${greet('World')} from ${appName}!`);
// Save these as src/config.ts, src/utils/helper.ts, src/index.ts

// ------------------------------------------------------------------

// After saving the files, run in your terminal:
// npm install
// npm run start

view raw JSON →