rollup-plugin-typescript3
raw JSON → 3.0.5 verified Mon Apr 27 auth: no javascript
Rollup plugin that compiles TypeScript using the TypeScript compiler (tsc), not Babel. Version 3.0.5 requires TypeScript ^5.0.4 as a peer dependency. It provides a straightforward integration with Rollup, supporting TypeScript's full type-checking and emits. Unlike @rollup/plugin-typescript, which uses Babel's TypeScript support, this plugin leverages the actual TypeScript API for more accurate type handling. It is maintained by the community and receives occasional updates.
Common errors
error Error: Could not load plugin 'rollup-plugin-typescript3' (imported by rollup.config.js) ↓
cause ESM-only package imported with CommonJS require without .default.
fix
Use dynamic import: const typescript = (await import('rollup-plugin-typescript3')).default; or set type: 'module' in package.json.
error Error: Cannot find module 'typescript' ↓
cause TypeScript peer dependency not installed.
fix
npm install --save-dev typescript@^5.0.4
error Error: Unexpected token: punc (.) ↓
cause TypeScript not configured to emit ES modules (e.g., module set to CommonJS).
fix
Set 'module': 'ESNext' in tsconfig.json.
Warnings
breaking The plugin does not use Babel; your tsconfig must match Rollup's expectations. ↓
fix Ensure tsconfig.json has 'module' set to 'ESNext' or 'ES2015' and 'moduleResolution' appropriate for Rollup.
breaking Version 3.0.0+ changed to ESM-only; require() will fail without .default. ↓
fix Use import or require('rollup-plugin-typescript3').default.
gotcha Files outside the project (e.g., in node_modules) are not compiled by default. ↓
fix Add 'include' in tsconfig or use the 'include' plugin option.
gotcha TypeScript error messages may reference internal tsc; they are not always user-friendly. ↓
fix Run tsc separately for better error formatting if needed.
deprecated Consider using @rollup/plugin-typescript (official) if you need active maintenance. ↓
fix Replace import with @rollup/plugin-typescript and adjust configuration.
Install
npm install rollup-plugin-typescript3 yarn add rollup-plugin-typescript3 pnpm add rollup-plugin-typescript3 Imports
- default (typescript function) wrong
const typescript = require('rollup-plugin-typescript3')correctimport typescript from 'rollup-plugin-typescript3' - default (in CommonJS) wrong
const typescript = require('rollup-plugin-typescript3')correctconst typescript = require('rollup-plugin-typescript3').default - TypeScriptOptions wrong
import { TypeScriptOptions } from 'rollup-plugin-typescript3'correctimport type { TypeScriptOptions } from 'rollup-plugin-typescript3' - Plugin
import { Plugin } from 'rollup'
Quickstart
// rollup.config.js
import typescript from 'rollup-plugin-typescript3';
export default {
input: 'src/index.ts',
output: {
dir: 'dist',
format: 'es',
},
plugins: [typescript()],
};