rollup-plugin-ts-paths
raw JSON → 1.0.5 verified Mon Apr 27 auth: no javascript
A Rollup plugin (v1.0.5) that resolves TypeScript path aliases defined in tsconfig.json to their actual file paths during bundling. It allows developers to use TypeScript's paths feature with Rollup, enabling clean imports like `import { Foo } from 'foo'` which maps to a source file path. The plugin is lightweight, has no external runtime dependencies, and must be placed before other Rollup plugins like commonjs to ensure correct resolution. However, it only supports the first entry in a paths array, and it is primarily useful for projects that first compile with tsc and then bundle with Rollup. The package ships TypeScript types and is maintained on GitHub.
Common errors
error Error: Cannot find module 'foo' ↓
cause Plugin not placed before other resolvers or tsconfig paths not configured correctly.
fix
Ensure tsConfigPaths() is first in plugins array and that foo is defined in tsconfig.json paths.
error TypeError: tsConfigPaths is not a function ↓
cause Using named import instead of default import.
fix
Use
import tsConfigPaths from 'rollup-plugin-ts-paths'. Warnings
gotcha Plugin only resolves the first entry in a tsconfig paths array; subsequent entries are ignored. ↓
fix Ensure the first path entry is the intended one, or avoid using multiple fallback paths.
gotcha Place before other Rollup plugins that resolve imports (like nodeResolve or commonjs), otherwise paths may not be resolved. ↓
fix Order the plugin first in the plugins array.
gotcha Requires tsconfig.json to be present; does not support jsconfig.json or alternative config files. ↓
fix Ensure tsconfig.json exists in the project root or specify tsConfigDirectory option.
Install
npm install rollup-plugin-ts-paths yarn add rollup-plugin-ts-paths pnpm add rollup-plugin-ts-paths Imports
- default wrong
const { tsConfigPaths } = require('rollup-plugin-ts-paths')correctimport tsConfigPaths from 'rollup-plugin-ts-paths' - TypeScript type: Options
import type { Options } from 'rollup-plugin-ts-paths'
Quickstart
// rollup.config.js
import tsConfigPaths from 'rollup-plugin-ts-paths';
import commonjs from '@rollup/plugin-commonjs';
import { nodeResolve } from '@rollup/plugin-node-resolve';
export default {
input: 'src/index.ts',
output: {
dir: 'dist',
format: 'esm'
},
plugins: [
tsConfigPaths(), // Must come before other resolvers
nodeResolve(),
commonjs()
]
}