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.
npm install rollup-plugin-typescript2Verified import paths — ran on the pinned version, not inferred.
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`.
Update your `tsconfig.json` to use `moduleResolution: 'node10'` or `node`.
Be aware of these overrides; do not attempt to configure these specific options in your `tsconfig.json` if you expect them to behave differently with this plugin. For `declarationDir`, consider the `useTsconfigDeclarationDir` plugin option.
Ensure `@rollup/plugin-node-resolve` precedes `rollup-plugin-typescript2` in your `rollup.config.js` plugin list.
Add `include: ["src/**/*.ts+(|x)", "src/**/*.js+(|x)"]` and `exclude: ["node_modules/**"]` to your plugin options if `allowJs` is enabled.
Upgrade to `0.37.0` or newer to resolve picomatch compatibility issues.
Upgrade `rollup-plugin-typescript2` to `0.34.1` or newer.
Upgrade `rollup-plugin-typescript2` to `0.32.1` or newer. This fix involved upgrading `@rollup/plugin-commonjs` to v22.
Upgrade `rollup-plugin-typescript2` to `0.34.0` or newer, which includes a fix for handling all type-only imports and ensuring proper type-checking and declaration generation for such files.
Change `moduleResolution` to `node` or `node10` in your `tsconfig.json`.