rollup-plugin-tsc-alias

raw JSON →
1.1.4 verified Mon Apr 27 auth: no javascript

A Rollup plugin that replaces TypeScript path aliases with relative paths after compilation using tsc-alias. Version 1.1.4 is the latest stable release. It integrates seamlessly into Rollup's build pipeline, reading aliases from tsconfig.json and rewriting import paths in the output bundle. Unlike manual path resolution, this plugin automates the mapping of TypeScript paths (e.g., @/components) to relative paths, ensuring compatibility with CommonJS and ESM output. It supports watch mode, custom config file paths, and options for declaration directories. The plugin is lightweight, with only Rollup as a peer dependency, and is actively maintained.

error Error: Could not resolve import "..." in "..." (via tsc-alias)
cause tsc-alias cannot find the target module based on the configured path aliases.
fix
Verify that tsconfig.json contains correct paths mapping and that the alias matches the import statement exactly.
error TypeError: Cannot read properties of undefined (reading 'compilerOptions')
cause tsconfig.json file not found or invalid JSON.
fix
Ensure configFile option points to a valid tsconfig.json file with compilerOptions.paths defined.
error Warning: The 'silent' option is deprecated and no longer has any effect.
cause Using the deprecated 'silent' option in plugin configuration.
fix
Remove the 'silent' key from the options object passed to tscAlias().
gotcha Plugin must run after TypeScript compilation. Order matters: place tscAlias after TypeScript plugin in Rollup plugins array.
fix Ensure the TypeScript plugin (e.g., @rollup/plugin-typescript) comes before tscAlias in the plugins array.
deprecated The 'silent' option is deprecated and has no effect since version 1.1.3.
fix Remove the 'silent' option from configuration. Use 'verbose' for output control.
gotcha If tsconfig.json uses path aliases with wildcards (e.g., '@/*'), resolveFullPaths must be set to true for ESM compatibility.
fix Set resolveFullPaths: true in tscAlias options when using wildcard aliases and targeting ESM format.
npm install rollup-plugin-tsc-alias
yarn add rollup-plugin-tsc-alias
pnpm add rollup-plugin-tsc-alias

Basic Rollup configuration integrating rollup-plugin-tsc-alias to resolve TypeScript path aliases in ESM output.

// rollup.config.js
import tscAlias from 'rollup-plugin-tsc-alias';

export default {
  input: 'src/index.ts',
  output: {
    dir: 'dist',
    format: 'esm',
  },
  plugins: [
    tscAlias({
      configFile: 'tsconfig.json',
      watch: false,
      outDir: undefined,
      declarationDir: undefined,
      resolveFullPaths: false,
      verbose: false,
    }),
  ],
};