rollup-plugin-typescript-paths is a Rollup plugin designed to automatically resolve TypeScript path aliases (defined in tsconfig.json's `paths` and `baseUrl` options) *after* your TypeScript code has already been transpiled. It is currently stable at version `1.5.0` and receives regular updates, with several minor releases in the past year addressing features and bug fixes. This plugin fills a specific niche for projects that use separate TypeScript transpilation steps (e.g., Babel, swc, tsc --emitDeclarationOnly) before bundling with Rollup, rather than relying on Rollup plugins that handle TypeScript compilation directly (like `rollup-plugin-typescript`). Its key differentiators include requiring no configuration for basic usage, robust wildcard support, and leveraging the official TypeScript API's `nodeModuleNameResolver` for accurate path resolution. It ensures that Rollup understands imports like `@utils/foo` when `tsconfig.json` maps `@utils/*` to `src/helpers/utils/*`.
npm install rollup-plugin-typescript-pathsVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to configure Rollup with `rollup-plugin-typescript-paths` to resolve TypeScript path aliases. It includes a runnable `rollup.config.js` and outlines the necessary `tsconfig.json` and source file structure to illustrate path resolution for `@utils` and `@components` aliases, assuming TypeScript transpilation (e.g., for declaration files) might occur in a separate step.
Update your import to `import { typescriptPaths } from 'rollup-plugin-typescript-paths';` and ensure you call it in your plugins array: `plugins: [typescriptPaths()]`.Ensure your build pipeline clearly separates transpilation and path resolution steps. If using `rollup-plugin-typescript`, configure it to only emit declaration files and let `rollup-plugin-typescript-paths` handle runtime path resolution.
Add `nonRelative: true` to the `typescriptPaths` plugin options: `typescriptPaths({ nonRelative: true })`.Review your Rollup output or module resolution results after updating to ensure all modules are correctly resolved. This fix generally improves resolution accuracy.
Update to `v1.2.3` or newer to benefit from the fix for parsing comments in `tsconfig.json`. Alternatively, remove any comments from your `tsconfig.json` if using an older version.
Ensure you are using the correct ESM named import: `import { typescriptPaths } from 'rollup-plugin-typescript-paths';` in your Rollup configuration file.Double-check your `compilerOptions.baseUrl` and `compilerOptions.paths` in `tsconfig.json`. If your `tsconfig.json` is not in the project root, specify its path using the `tsConfigPath` option (e.g., `typescriptPaths({ tsConfigPath: './configs/tsconfig.build.json' })`). For non-relative imports based on `baseUrl` without specific `paths` entries, set `nonRelative: true` in the plugin options.Ensure you call the plugin function when adding it to your plugins array: `plugins: [typescriptPaths()]` instead of `plugins: [typescriptPaths]`.