rollup-plugin-ts-compiler
raw JSON → 1.0.18 verified Mon Apr 27 auth: no javascript
A TypeScript compiler plugin for Rollup that uses the TypeScript Compiler API with incremental program for fast compilation. Version 1.0.18 is stable. The plugin supports compiler errors, incremental builds, declarations, source maps, and monorepo setups. It differs from alternatives like rollup-plugin-typescript2 and @rollup/plugin-typescript by using modern TypeScript APIs for performance, but at the cost of bypassing Rollup's preceding pipeline.
Common errors
error Error [ERR_REQUIRE_ESM]: require() of ES Module not supported ↓
cause Using CommonJS require() to load the ESM-only library.
fix
Switch to ESM (e.g., add 'type': 'module' in package.json) or use dynamic import().
error TypeError: typescript is not a function ↓
cause Using named import 'typescript' instead of default import.
fix
Use default import: import typescript from 'rollup-plugin-ts-compiler'
error The 'compilerOptions' option does not match tsconfig.json: 'module' can only be 'ES2015', 'ES2020', 'ESNext', etc. when target is 'ESNext'. ↓
cause Incompatible compilerOptions override violating TypeScript rules.
fix
Ensure the overridden options are valid according to TypeScript's constraints.
Warnings
gotcha Bypasses Rollup's preceding pipeline: the plugin reads .ts files directly from the filesystem, ignoring any previous Rollup plugins that modify TypeScript source code. ↓
fix Place this plugin before any other plugins that need to transform TypeScript code, or be aware that earlier plugins won't affect compiled output.
breaking Named export removed in v1.0.0: prior versions exported a named function 'typescript', but now the default export is the plugin function. ↓
fix Use default import: import typescript from 'rollup-plugin-ts-compiler'
gotcha Monorepo mode can cause unnecessary recompilation: setting 'monorepo: true' forces the plugin to watch and recompile files outside the project root, which may include large node_modules in non-monorepo contexts. ↓
fix Only enable monorepo when you have local packages in a monorepo; otherwise leave it false.
deprecated Shared state via 'sharedState' option may be deprecated in future versions. No official deprecation notice, but consider using Rollup's native caching mechanisms. ↓
fix Avoid relying on sharedState for long-term; monitor releases for alternatives.
Install
npm install rollup-plugin-ts-compiler yarn add rollup-plugin-ts-compiler pnpm add rollup-plugin-ts-compiler Imports
- default wrong
const typescript = require('rollup-plugin-ts-compiler')correctimport typescript from 'rollup-plugin-ts-compiler' - typescript wrong
import { typescript } from 'rollup-plugin-ts-compiler'correctimport typescript from 'rollup-plugin-ts-compiler' - TypeScriptPluginOptions wrong
import { TypeScriptPluginOptions } from 'rollup-plugin-ts-compiler' (without type)correctimport type { TypeScriptPluginOptions } from 'rollup-plugin-ts-compiler'
Quickstart
import typescript from 'rollup-plugin-ts-compiler';
export default {
input: './src/index.ts',
output: {
file: './dist/bundle.js',
format: 'esm'
},
plugins: [
typescript({
compilerOptions: {
target: 'es2020',
module: 'esnext'
}
})
]
};