Sign Up for Free

RunKit +

Try any Node.js package right in your browser

This is a playground to test code. It runs a full Node.js environment and already has all of npm’s 400,000 packages pre-installed, including @zerollup/ts-transform-paths with all npm packages installed. Try it out:

require("typescript/package.json"); // typescript is a peer dependency. var tsTransformPaths = require("@zerollup/ts-transform-paths")

This service is provided by RunKit and is not affiliated with npm, Inc or the package authors.

@zerollup/ts-transform-paths v1.7.11

Ts transform paths

Typescript transform paths plugin

Heavily tested and most complete import/require path rewriter for typescript.

tsconfig baseUrl + paths alias rewriting in bundles and declaration files. You can use absolute paths in libraries. All them will be rewritted to relative in transpiled js and in d.ts files.

Works everywhere, no more tspath, rollup-plugin-alias or webpack resolve alias and other workarounds.

Why? Problem described here: d.ts files not working, if absolute paths used in npm-packaged library.

Similar libraries

ts-transform-import-path-rewrite does't support compilerOptions.paths config, doesn't support require function, weak tested.

ts-transformer-imports doesn't support dynamic import and require function. It doesn't support d.ts: "transform": "ts-transformer-imports", "afterDeclarations" true, "before": "true"} rewrites paths only in d.ts, "transform": "ts-transformer-imports", "afterDeclarations" true, "after": "true"} rewrites paths only in js.

External packages

Since 1.7.4 plugin rewrites paths only in internal project files, not for packages in node_modules.

// tsconfig.json
  "compilerOptions": {
    "baseUrl": "src"
    "plugins": [{ "transform": "@zerollup/ts-transform-paths" }],
    "paths": { "*": ["*"] },

// main.ts
import { app } from "electron";  // a module in node_modules
import { setMenu } from "main/menu";  // a module in the current dir

// main.js
const electron_1 = require("electron");
const menu_1 = require("./main/menu");

Setup For ttypescript

ttypescript is a wrapper around typescript with transformer plugin support in tsconfig.json.


    "compilerOptions": {
        "baseUrl": ".",
        "paths": {
            "my-lib/*": ["src/*"]
        "plugins": [
                "transform": "@zerollup/ts-transform-paths",
                "exclude": ["*"]


export * from 'my-lib/some'


export const some = '123'

Transpiled my-lib/dist/index.js

export * from './some'

Typings my-lib/dist/index.d.ts

export * from './some';

For more examples see zerollup demo lib.

Setup For rollup-plugin-typescript2


$ npm i -D @zerollup/ts-transform-paths

add to configure file rollup.config.js

import typescript from 'rollup-plugin-typescript2'
import transformPaths from '@zerollup/ts-transform-paths'

export default {
    input: 'src/lib.ts',
    output: [{ file : 'dist/lib.js', name : 'mylib', format : 'iife', sourcemap : true }],
    plugins: typescript({
        useTsconfigDeclarationDir : true,
        cacheRoot : '.cache',
        tsconfig : 'tsconfig.json',
        transformers: [service => transformPaths(service.getProgram())]
        // transformers: [service => transformPaths(service.getProgram(), { exclude: ['*'] })] // has config

Setup For webpack ts-loader

const tsTransformPaths = require('@zerollup/ts-transform-paths');

module.exports = {
  module: {
    rules: [
        test: /\.(ts|tsx)$/,
        loader: 'ts-loader',
        options: {
          getCustomTransformers: (program) => {
            const transformer = tsTransformPaths(program);
            return {
              before: [transformer.before], // for updating paths in generated code
              afterDeclarations: [transformer.afterDeclarations] // for updating paths in declaration files

Plugin options

interface Config {
        Disable plugin path resolving for given paths keys
    exclude?: string[] | void
RunKit is a free, in-browser JavaScript dev environment for prototyping Node.js code, with every npm package installed. Sign up to share your code.
Sign Up for Free