Replace absolute paths to relative paths after typescript compilation
Last updated 7 months ago by halkeye .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install @halkeye/tscpaths 
SYNC missed versions from official npm registry.


Replace absolute paths to relative paths after typescript compilation (tsc) during compile-time.

npm version Dependency Status License

Comparison to tsconfig-paths

+ Compile time (no runtime dependencies)

Getting Started

First, install tscpaths as devDependency using npm or yarn.

npm install --save-dev tscpaths
# or
yarn add -D tscpaths

Add it to your build scripts in package.json

"scripts": {
  "build": "tsc --project tsconfig.json && tscpaths --project tsconfig.json",

Building only the types

You can also setup a seperate tsconfig file just for types like tsconfig.types.json if you are also compiling with Babel.

// tsconfig.types.json
  "extends": "./tsconfig",
  "compilerOptions": {
    "module": "amd",
    "outDir": "dist",
    "rootDir": "./src",
    "declaration": true,
    "declarationMap": false,
    "isolatedModules": false,
    "noEmit": false,
    "allowJs": false,
    "emitDeclarationOnly": true
  "exclude": ["**/*.test.ts"]

And then target that

"scripts": {
  "build:types": "tsc --project tsconfig.types.json && tscpaths -project tsconfig.types.json",

Your final build script might look like

"scripts": {
  "build": "yarn build:commonjs && yarn build:types",


flag description
-p --project project configuration file (tsconfig.json)
-s --src source code root directory (overrides the tsconfig provided)
-o --out output directory of transpiled code (tsc --outDir) (overrides the tsconfig provided)
-v --verbose console.log all the events


This is not a mature project yet. Pull Requests are welcome!

It works for my setup so far.

It may not work correctly if your setup is too complicated, so please do some testing before pushing it to production!!!


You need to provide -s (--src) and -o (--out), because it's hard to predict source and output paths based on tsconfig.json.

I've tried a little and failed. :(

The above is no longer neccesary <-- got you fam: @jonkwheeler

Current Tags

  • 0.0.9                                ...           latest (7 months ago)

1 Versions

  • 0.0.9                                ...           7 months ago
Maintainers (1)
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 1
Dependencies (2)
Dev Dependencies (9)
Dependents (0)

Copyright 2014 - 2017 © taobao.org |