{"id":12775,"library":"rollup-plugin-typescript2","title":"Rollup Plugin for TypeScript with Error Diagnostics","description":"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.","status":"active","version":"0.37.0","language":"javascript","source_language":"en","source_url":"https://github.com/ezolenko/rollup-plugin-typescript2","tags":["javascript","rollup-plugin-typescript2","rollup-plugin-typescript","rollup-plugin","typescript","es2015","rollup","npm"],"install":[{"cmd":"npm install rollup-plugin-typescript2","lang":"bash","label":"npm"},{"cmd":"yarn add rollup-plugin-typescript2","lang":"bash","label":"yarn"},{"cmd":"pnpm add rollup-plugin-typescript2","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Peer dependency required for Rollup builds.","package":"rollup","optional":false},{"reason":"Peer dependency providing the TypeScript compiler.","package":"typescript","optional":false},{"reason":"Runtime dependency for emitting TypeScript helper functions efficiently.","package":"tslib","optional":false}],"imports":[{"note":"The plugin is exported as a default export.","wrong":"import { typescript } from 'rollup-plugin-typescript2';","symbol":"typescript","correct":"import typescript from 'rollup-plugin-typescript2';"},{"note":"For CommonJS environments, use `require` to import the default export.","symbol":"typescript (CommonJS)","correct":"const typescript = require('rollup-plugin-typescript2');"},{"note":"Options are passed directly to the default export function. TypeScript types are provided for these options.","symbol":"Plugin options","correct":"typescript({ tsconfig: './tsconfig.build.json' })"}],"quickstart":{"code":"import typescript from 'rollup-plugin-typescript2';\nimport { readFileSync } from 'node:fs';\nimport { join } from 'node:path';\n\nconst pkg = JSON.parse(readFileSync(join(process.cwd(), 'package.json'), 'utf8'));\n\nexport default {\n  input: 'src/index.ts',\n  output: [\n    {\n      file: pkg.main,\n      format: 'cjs',\n      sourcemap: true\n    },\n    {\n      file: pkg.module,\n      format: 'es',\n      sourcemap: true\n    }\n  ],\n  plugins: [\n    typescript({\n      tsconfig: './tsconfig.json',\n      typescript: require('typescript') // Ensure using the correct TypeScript version\n    })\n  ],\n  external: Object.keys(pkg.dependencies || {}).concat(Object.keys(pkg.peerDependencies || {}))\n};\n","lang":"typescript","description":"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`."},"warnings":[{"fix":"Update your `tsconfig.json` to use `moduleResolution: 'node10'` or `node`.","message":"The `moduleResolution: 'classic'` compiler option is deprecated by TypeScript and will be remapped to `node10` by this plugin. Using 'classic' can also lead to build failures.","severity":"breaking","affected_versions":">=0.12.0"},{"fix":"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.","message":"Certain TypeScript compiler options are forcibly overridden by `rollup-plugin-typescript2` for proper integration with Rollup. These include `noEmitHelpers: false`, `importHelpers: true`, `noResolve: false`, `noEmit: false`, `noEmitOnError: false`, `inlineSourceMap: false`, and `outDir`.","severity":"gotcha","affected_versions":">=0.1.0"},{"fix":"Ensure `@rollup/plugin-node-resolve` precedes `rollup-plugin-typescript2` in your `rollup.config.js` plugin list.","message":"When using `@rollup/plugin-node-resolve` (especially with `browser: true`), it must be placed *before* `rollup-plugin-typescript2` in your Rollup plugins array to ensure correct module resolution.","severity":"gotcha","affected_versions":">=0.1.0"},{"fix":"Add `include: [\"src/**/*.ts+(|x)\", \"src/**/*.js+(|x)\"]` and `exclude: [\"node_modules/**\"]` to your plugin options if `allowJs` is enabled.","message":"If `allowJs` is enabled in your `tsconfig.json` to process JavaScript files, you must explicitly modify the plugin's `include` option to add `\"*.js+(|x)\", \"**/*.js+(|x)\"`. Failing to `exclude` `node_modules` in this scenario can significantly slow down builds.","severity":"gotcha","affected_versions":">=0.1.0"},{"fix":"Upgrade to `0.37.0` or newer to resolve picomatch compatibility issues.","message":"Version `0.37.0` included a bugfix for picomatch 2.3.2 compatibility, replacing `+(|x)` patterns with `{,x}`. If you encounter issues with file matching or includes after upgrading picomatch, this might be related.","severity":"gotcha","affected_versions":">=0.37.0"}],"env_vars":null,"last_verified":"2026-04-19T00:00:00.000Z","next_check":"2026-07-18T00:00:00.000Z","problems":[{"fix":"Upgrade `rollup-plugin-typescript2` to `0.34.1` or newer.","cause":"A regression in `0.34.0` caused actual initialization errors (e.g., `tsconfig` issues) to be masked by this generic error.","error":"TypeError: Cannot read property 'done' of undefined"},{"fix":"Upgrade `rollup-plugin-typescript2` to `0.32.1` or newer. This fix involved upgrading `@rollup/plugin-commonjs` to v22.","cause":"A regression in `0.32.0` caused this error in certain environments due to issues with `@rollup/plugin-commonjs` try/catch requires.","error":"ReferenceError: window is not defined"},{"fix":"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.","cause":"Older versions of the plugin might not correctly handle type-only/interface-only files that produce no JavaScript output, leading to missed type checks or declaration generation.","error":"Some files are not type-checked or declarations are not generated, especially for type-only files."},{"fix":"Change `moduleResolution` to `node` or `node10` in your `tsconfig.json`.","cause":"The `classic` module resolution strategy is deprecated by TypeScript and can cause compatibility issues with `rollup-plugin-typescript2`.","error":"Build fails with `moduleResolution: 'classic'`"}],"ecosystem":"npm"}