justkey007/tsc-alias

Replace alias paths with relative paths after typescript compilation

TypeScript

1,143

317 commits

updated Sep 30, 2026

See the code

README

tsc-alias

Replace alias paths with relative paths after typescript compilation. You can add aliases that reference other projects outside your tsconfig.json project by providing a relative path to the baseUrl.

npm version License Build Status

Comparison to tsconfig-paths

+ Compile time (no runtime dependencies)

Getting Started

First, install tsc-alias as devDependency using npm.

npm install -g tsc-alias
npm install --save-dev tsc-alias

Add it to your build scripts in package.json

"scripts": {
  "build": "tsc --project tsconfig.json && tsc-alias -p tsconfig.json",
}

or

"scripts": {
  "build": "tsc && tsc-alias",
  "build:watch": "tsc && (concurrently \"tsc -w\" \"tsc-alias -w\")"
}

CLI

To display all available options:

tsc-alias --help

Issues

If you have an issue, please create one. But, before:

  • try to check the FAQ.
  • try to check if there are any related issues
  • try to run with --debug and check if config is correctly loaded and all sourcefiles are found.

API

Installation

npm install tsc-alias

Usage

import { replaceTscAliasPaths } from 'tsc-alias';

replaceTscAliasPaths(options?);

Here are all the available options:

OptionDescriptionDefault Value
project, ppath to tsconfig.json'tsconfig.json'
watchObserve file changesfalse
outDirRun in a folder leaving the "outDir" of the tsconfig.json (relative path to tsconfig)tsconfig.compilerOptions.outDir
declarationDirWorks the same as outDir but for declarationDirtsconfig.compilerOptions.declarationDir
followReferencesIf true, tsc-alias will follow TypeScript project references defined in tsconfig.json and run alias replacement on all referenced projects.false
resolveFullPathsAttempt to replace incomplete import paths (those not ending in .js) with fully resolved paths (for ECMAScript Modules compatibility)false
resolveFullExtensionAllows you to specify the extension of incomplete import paths, works with resolveFullPaths'.js' | '.mjs' | '.cjs'
silentReduced terminal output. This is a deprecated option and no longer has any effect.true
verboseAdditional information is output to the terminalfalse
debugDebug information is send to the terminalfalse
replacersFiles to import as extra replacers More info[]
outputThe output object tsc-alias will send logs to.new Output(options.verbose)
fileExtensionsOverwrite file extensions tsc-alias will use to scan and resolve files.undefined

Configuration via tsconfig.json Example

{
  "compilerOptions": {
    ...
  },
  "tsc-alias": {
    "verbose": false,
    "resolveFullPaths": true,
    "replacers": {
      "exampleReplacer": {
        "enabled": true,
        "file": "./exampleReplacer.js"
      },
      "otherReplacer": {
        "enabled": true,
        "file": "./otherReplacer.js"
      }
    },
    "fileExtensions": {
      "inputGlob": "{js,jsx,mjs}",
      "outputCheck": ["js", "json", "jsx", "mjs"]
    }
  }
}

Single file replacer

We can use tsc-alias in a single file, with a function that returns the modified contents.

We prepare the replacer with prepareSingleFileReplaceTscAliasPaths(), passing the same options that we would pass to replaceTscAliasPaths(). That will return a promise of a function that receives the file contents and path, and returns the transformed contents, synchronously.

import { prepareSingleFileReplaceTscAliasPaths } from 'tsc-alias';

const runFile: SingleFileReplacer = await prepareSingleFileReplaceTscAliasPaths(options?);

function treatFile(filePath: string) {
  const fileContents = fs.readFileSync(filePath, 'utf8');
  const newContents = runFile({fileContents, filePath});
  // do stuff with newContents
}
absolute-path
alias
compilation
paths
relative-path
tsc
typescript

justkey007/tsc-alias

Replace alias paths with relative paths after typescript compilation

TypeScript

1,143

317 commits

updated Sep 30, 2026

See the code

README

tsc-alias

Replace alias paths with relative paths after typescript compilation. You can add aliases that reference other projects outside your tsconfig.json project by providing a relative path to the baseUrl.

npm version License Build Status

Comparison to tsconfig-paths

+ Compile time (no runtime dependencies)

Getting Started

First, install tsc-alias as devDependency using npm.

npm install -g tsc-alias
npm install --save-dev tsc-alias

Add it to your build scripts in package.json

"scripts": {
  "build": "tsc --project tsconfig.json && tsc-alias -p tsconfig.json",
}

or

"scripts": {
  "build": "tsc && tsc-alias",
  "build:watch": "tsc && (concurrently \"tsc -w\" \"tsc-alias -w\")"
}

CLI

To display all available options:

tsc-alias --help

Issues

If you have an issue, please create one. But, before:

  • try to check the FAQ.
  • try to check if there are any related issues
  • try to run with --debug and check if config is correctly loaded and all sourcefiles are found.

API

Installation

npm install tsc-alias

Usage

import { replaceTscAliasPaths } from 'tsc-alias';

replaceTscAliasPaths(options?);

Here are all the available options:

OptionDescriptionDefault Value
project, ppath to tsconfig.json'tsconfig.json'
watchObserve file changesfalse
outDirRun in a folder leaving the "outDir" of the tsconfig.json (relative path to tsconfig)tsconfig.compilerOptions.outDir
declarationDirWorks the same as outDir but for declarationDirtsconfig.compilerOptions.declarationDir
followReferencesIf true, tsc-alias will follow TypeScript project references defined in tsconfig.json and run alias replacement on all referenced projects.false
resolveFullPathsAttempt to replace incomplete import paths (those not ending in .js) with fully resolved paths (for ECMAScript Modules compatibility)false
resolveFullExtensionAllows you to specify the extension of incomplete import paths, works with resolveFullPaths'.js' | '.mjs' | '.cjs'
silentReduced terminal output. This is a deprecated option and no longer has any effect.true
verboseAdditional information is output to the terminalfalse
debugDebug information is send to the terminalfalse
replacersFiles to import as extra replacers More info[]
outputThe output object tsc-alias will send logs to.new Output(options.verbose)
fileExtensionsOverwrite file extensions tsc-alias will use to scan and resolve files.undefined

Configuration via tsconfig.json Example

{
  "compilerOptions": {
    ...
  },
  "tsc-alias": {
    "verbose": false,
    "resolveFullPaths": true,
    "replacers": {
      "exampleReplacer": {
        "enabled": true,
        "file": "./exampleReplacer.js"
      },
      "otherReplacer": {
        "enabled": true,
        "file": "./otherReplacer.js"
      }
    },
    "fileExtensions": {
      "inputGlob": "{js,jsx,mjs}",
      "outputCheck": ["js", "json", "jsx", "mjs"]
    }
  }
}

Single file replacer

We can use tsc-alias in a single file, with a function that returns the modified contents.

We prepare the replacer with prepareSingleFileReplaceTscAliasPaths(), passing the same options that we would pass to replaceTscAliasPaths(). That will return a promise of a function that receives the file contents and path, and returns the transformed contents, synchronously.

import { prepareSingleFileReplaceTscAliasPaths } from 'tsc-alias';

const runFile: SingleFileReplacer = await prepareSingleFileReplaceTscAliasPaths(options?);

function treatFile(filePath: string) {
  const fileContents = fs.readFileSync(filePath, 'utf8');
  const newContents = runFile({fileContents, filePath});
  // do stuff with newContents
}
absolute-path
alias
compilation
paths
relative-path
tsc
typescript

Project health

Overall

5.0/10

Maintained

10/10

Code review

0/10
OpenSSF Scorecard

Latest release

1.9.7 · Sep 30, 2026

Releases this year

9

Significant stargazers

C. T. Lin

1,952 followers · starred Oct 2025

Anton Kastritskii

219 followers · starred May 2024

Munif Tanjim

578 followers · starred Sep 2023

Jeon Suyeol

4,035 followers · starred Feb 2026