rollup-plugin-generate-declarations

raw JSON →
1.1.2 verified Mon Apr 27 auth: no javascript

A simple Rollup plugin that runs `tsc --emitDeclarationOnly` during build to generate `.d.ts` declaration files, solving the common problem of missing declarations when using Babel to transpile TypeScript. Current stable version is 1.1.2. Releases are infrequent. Key differentiator: integrates declaraton generation directly into Rollup pipeline, avoiding separate `tsc` step. Alternatives like `rollup-plugin-dts` generate declarations from compiled bundles; this plugin uses TypeScript compiler directly for more accurate declarations.

error Error: Cannot find module 'rollup-plugin-generate-declarations'
cause Missing or incomplete install; missing peer deps.
fix
Run npm install rollup-plugin-generate-declarations --save-dev and ensure rollup and typescript are installed.
error TypeError: generateDeclarations is not a function
cause Used named import instead of default import (e.g., import { generateDeclarations }).
fix
Use default import: import generateDeclarations from ...
error Error: The 'rollup' version (x.x.x) does not satisfy the peer dependency requirement (>=2.30.0)
cause Incompatible Rollup version.
fix
Upgrade Rollup to >=2.30.0.
gotcha Plugin runs `tsc --emitDeclarationOnly` after rollup bundle, potentially overwriting declarations from other plugin if ordering is incorrect.
fix Ensure generateDeclarations is placed after typescript compilation plugins in plugins array.
breaking Version 1.0.0 changed from CJS to ESM; require() may fail without wrapper.
fix Use dynamic import or set "type": "module" in package.json for Node.js.
deprecated Plugin does not support Rollup's watch mode; declarations may not regenerate on file changes.
fix For watch mode, use tsc separately or combine with @rollup/plugin-typescript's declaration setting.
npm install rollup-plugin-generate-declarations
yarn add rollup-plugin-generate-declarations
pnpm add rollup-plugin-generate-declarations

Shows basic usage with @rollup/plugin-typescript; generates .d.ts files for TypeScript source.

import generateDeclarations from 'rollup-plugin-generate-declarations';
import typescript from '@rollup/plugin-typescript';

export default {
  input: 'src/index.ts',
  output: {
    dir: 'dist',
    format: 'esm'
  },
  plugins: [
    typescript(),
    generateDeclarations()
  ]
};