Registry / type-stubs / rollup-plugin-typescript2

rollup-plugin-typescript2

JSON →
library0.37.0jsnpmunverified

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-typescript2
INSTALL
IMPORT
SIG · ROLLUP-PLUGIN-TYPE
R
rollup-plugin-typescript2
type-stubsjavascriptv0.37.0
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

typescript
import typescript from 'rollup-plugin-typescript2';
import { typescript } from 'rollup-plugin-typescript2';
The plugin is exported as a default export.
typescript (CommonJS)
const typescript = require('rollup-plugin-typescript2');
For CommonJS environments, use `require` to import the default export.
Plugin options
typescript({ tsconfig: './tsconfig.build.json' })
Options are passed directly to the default export function. TypeScript types are provided for these options.

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 || {})) };
Debug
Known issues
breakingThe `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.
fix
Update your `tsconfig.json` to use `moduleResolution: 'node10'` or `node`.
affects: >=0.12.0
gotchaCertain 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`.
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.
affects: >=0.1.0
gotchaWhen 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.
fix
Ensure `@rollup/plugin-node-resolve` precedes `rollup-plugin-typescript2` in your `rollup.config.js` plugin list.
affects: >=0.1.0
gotchaIf `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.
fix
Add `include: ["src/**/*.ts+(|x)", "src/**/*.js+(|x)"]` and `exclude: ["node_modules/**"]` to your plugin options if `allowJs` is enabled.
affects: >=0.1.0
gotchaVersion `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.
fix
Upgrade to `0.37.0` or newer to resolve picomatch compatibility issues.
affects: >=0.37.0
Errors
Common errors & fixes
TypeError: Cannot read property 'done' of undefined
A regression in `0.34.0` caused actual initialization errors (e.g., `tsconfig` issues) to be masked by this generic error.
fix
Upgrade `rollup-plugin-typescript2` to `0.34.1` or newer.
ReferenceError: window is not defined
A regression in `0.32.0` caused this error in certain environments due to issues with `@rollup/plugin-commonjs` try/catch requires.
fix
Upgrade `rollup-plugin-typescript2` to `0.32.1` or newer. This fix involved upgrading `@rollup/plugin-commonjs` to v22.
Some files are not type-checked or declarations are not generated, especially for type-only files.
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.
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.
Build fails with `moduleResolution: 'classic'`
The `classic` module resolution strategy is deprecated by TypeScript and can cause compatibility issues with `rollup-plugin-typescript2`.
fix
Change `moduleResolution` to `node` or `node10` in your `tsconfig.json`.
Upgrade
Version history
0.37.0latest on npm
Audit
Dependencies
rolluprequiredPeer dependency required for Rollup builds.
typescriptrequiredPeer dependency providing the TypeScript compiler.
tslibrequiredRuntime dependency for emitting TypeScript helper functions efficiently.
Agent activity
25 hits · last 30 days
node
22
Amazon
1
OpenAI (training)
1
Resources