Rollup Plugin for TypeScript with Error Diagnostics

0.37.0 · active · verified Sun Apr 19

rollup-plugin-typescript2 is a Rollup plugin that integrates TypeScript compilation into the Rollup build process, with a primary focus on correctly reporting TypeScript syntactic and semantic diagnostic messages. It is a rewrite of the original `rollup-plugin-typescript`, offering more robust error reporting at the cost of being somewhat slower. The current stable version is 0.37.0, with releases occurring every few months, indicating active maintenance and ongoing compatibility updates with newer TypeScript versions (e.g., supporting TS 5.x since 0.36.0 and newer `moduleResolution` kinds). The plugin inherits most compiler options and file lists directly from `tsconfig.json`, but enforces or modifies a few specific options for optimal Rollup integration, such as `noEmit`, `noEmitOnError`, and `outDir` handling. It differentiates itself by ensuring comprehensive TypeScript error reporting, which was a limitation of its predecessors.

Common errors

Warnings

Install

Imports

Quickstart

This configuration demonstrates how to integrate `rollup-plugin-typescript2` into a Rollup build, compiling a TypeScript entry point into both CommonJS and ES module formats, respecting a `tsconfig.json` file, and handling external dependencies defined in `package.json`.

import typescript from 'rollup-plugin-typescript2';
import { readFileSync } from 'node:fs';
import { join } from 'node:path';

const pkg = JSON.parse(readFileSync(join(process.cwd(), 'package.json'), 'utf8'));

export default {
  input: 'src/index.ts',
  output: [
    {
      file: pkg.main,
      format: 'cjs',
      sourcemap: true
    },
    {
      file: pkg.module,
      format: 'es',
      sourcemap: true
    }
  ],
  plugins: [
    typescript({
      tsconfig: './tsconfig.json',
      typescript: require('typescript') // Ensure using the correct TypeScript version
    })
  ],
  external: Object.keys(pkg.dependencies || {}).concat(Object.keys(pkg.peerDependencies || {}))
};

view raw JSON →