# tsc-alias

> Replace alias paths with relative paths after typescript compilation.

Latest version **1.9.5** (published 2026-09-11) · MIT license · 0 weekly downloads

## Install

```sh
npm install tsc-alias
pnpm add tsc-alias
yarn add tsc-alias
bun add tsc-alias
```

Provides the command `tsc-alias`.

## Health

**Score 65/100 (B)** — status: active.

Positive: has types; no vulnerabilities; recently updated; high maintenance score; high quality score.

Warnings: low downloads; no esm support.

## Facts

| | |
|---|---|
| Version | 1.9.5 |
| Published | 2026-09-11 |
| First published | 2019-05-05 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Node | >=16.20.2 |
| Dependencies | 7 |
| Unpacked size | 231.6 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 1140 |
| Author | Juskey B. |
| Maintainers | justkey |
| Keywords | typescript, paths, alias, absolute path, relative path, compilation, tsc |

## Links

- npm: https://www.npmjs.com/package/tsc-alias
- Repository: https://github.com/justkey007/tsc-alias
- Homepage: https://github.com/justkey007/tsc-alias.git
- Issues: https://github.com/justkey007/tsc-alias/issues
- Funding: https://github.com/sponsors/justkey007
- npm.io page: https://npm.io/package/tsc-alias

## Dependencies (7)

- [mylas](https://npm.io/package/mylas.md) ^2.1.9
- [globby](https://npm.io/package/globby.md) ^11.0.4
- [chokidar](https://npm.io/package/chokidar.md) ^3.5.3
- [commander](https://npm.io/package/commander.md) ^9.0.0
- [plimit-lit](https://npm.io/package/plimit-lit.md) ^1.2.6
- [get-tsconfig](https://npm.io/package/get-tsconfig.md) ^4.10.0
- [normalize-path](https://npm.io/package/normalize-path.md) ^3.0.0

## Alternatives

- [base64url](https://npm.io/package/base64url.md) — 6.1M weekly downloads
- [get-installed-path](https://npm.io/package/get-installed-path.md) — 502.9K weekly downloads
- [@uppy/url](https://npm.io/package/@uppy/url.md) — 185.8K weekly downloads
- [@d3fc/d3fc-shape](https://npm.io/package/@d3fc/d3fc-shape.md) — 16.2K weekly downloads
- [localizer](https://npm.io/package/localizer.md) — 226 weekly downloads

## Recent versions

- 1.9.5 (latest) — 2026-09-11
- 1.9.4 — 2026-09-02
- 1.9.3 — 2026-08-31
- 1.9.2 — 2026-08-17
- 1.9.1 — 2026-07-13
- 1.9.0 — 2026-07-04
- 1.8.17 — 2026-05-01
- 1.8.16 — 2025-05-05
- 1.8.15 — 2025-04-10
- 1.8.14 — 2025-04-08
- 1.8.13 — 2025-03-29
- 1.8.12 — 2025-03-29
- 1.8.11 — 2025-02-25
- 1.8.10 — 2024-05-13
- 1.8.9 — 2024-05-10
- … 70 more at https://npm.io/package/tsc-alias/versions

## 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](https://badge.fury.io/js/tsc-alias.svg)](https://badge.fury.io/js/tsc-alias)
[![License](https://img.shields.io/:license-mit-blue.svg)](http://doge.mit-license.org)
![Build Status](https://img.shields.io/badge/tests-passing-brightgreen)
[![](https://img.shields.io/static/v1?label=Sponsor&message=%E2%9D%A4&logo=GitHub&color=%23fe8e86)](https://github.com/sponsors/justkey007)

## Comparison to [tsconfig-paths](https://github.com/dividab/tsconfig-paths)

\+ Compile time (no runtime dependencies)

## Getting Started

First, install tsc-alias as devDependency using npm.

```sh
npm install -g tsc-alias
```

```sh
npm install --save-dev tsc-alias
```

## Add it to your build scripts in package.json

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

or

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

### CLI

To display all available options:

```sh
tsc-alias --help
```

## Issues

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

- try to check the [FAQ.](https://github.com/justkey007/tsc-alias/discussions/110)
- 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

```sh
npm install tsc-alias
```

### Usage

```typescript
import { replaceTscAliasPaths } from 'tsc-alias';

replaceTscAliasPaths(options?);
```

Here are all the available options:

<table>
  <thead>
  <tr>
    <th>Option</th>
    <th>Description</th>
    <th>Default Value</th>
  </tr>
  </thead>
  <tbody>
    <tr>
      <td>project, p</td>
      <td>path to tsconfig.json</td>
      <td><code>'tsconfig.json'</code></td>
    </tr>
    <tr>
      <td>watch</td>
      <td>Observe file changes</td>
      <td><code>false</code></td>
    </tr>
    <tr>
      <td>outDir</td>
      <td>Run in a folder leaving the "outDir" of the tsconfig.json (relative path to tsconfig)</td>
      <td><code>tsconfig.compilerOptions.outDir</code></td>
    </tr>
    <tr>
      <td>declarationDir</td>
      <td>Works the same as outDir but for declarationDir</td>
      <td><code>tsconfig.compilerOptions.declarationDir</code></td>
    </tr>
    <tr>
      <td>followReferences</td>
      <td>If true, tsc-alias will follow TypeScript project references defined in tsconfig.json and run alias replacement on all referenced projects.</td>
      <td><code>false</code></td>
    </tr>
    <tr>
      <td>resolveFullPaths</td>
      <td>Attempt to replace incomplete import paths (those not ending in <code>.js</code>) with fully resolved paths (for ECMAScript Modules compatibility)</td>
      <td><code>false</code></td>
    </tr>
    <tr>
      <td>resolveFullExtension</td>
      <td>Allows you to specify the extension of incomplete import paths, works with <code>resolveFullPaths</code></td>
      <td><code>'.js' | '.mjs' | '.cjs'</code></td>
    </tr>
    <tr>
      <td>silent</td>
      <td>Reduced terminal output. This is a deprecated option and no longer has any effect.</td>
      <td><code>true</code></td>
    </tr>
    <tr>
      <td>verbose</td>
      <td>Additional information is output to the terminal</td>
      <td><code>false</code></td>
    </tr>
    <tr>
      <td>debug</td>
      <td>Debug information is send to the terminal</td>
      <td><code>false</code></td>
    </tr>
    <tr>
      <td>replacers</td>
      <td>Files to import as extra replacers <a href="https://github.com/justkey007/tsc-alias/discussions/73">More info</a></td>
      <td><code>[]</code></td>
    </tr>
    <tr>
      <td>output</td>
      <td>The output object tsc-alias will send logs to.</td>
      <td><code>new Output(options.verbose)</code></td>
    </tr>
    <tr>
      <td>fileExtensions</td>
      <td>Overwrite file extensions tsc-alias will use to scan and resolve files.</td>
      <td><code>undefined</code></td>
    </tr>
  </tbody>
</table>

### Configuration via `tsconfig.json` Example

```json
{
  "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.

```typescript
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
}
```

---
_Source: https://npm.io/package/tsc-alias · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
