{"id":16524,"library":"rollup-plugin-api-extractor","title":"Rollup API Extractor Plugin","description":"The `rollup-plugin-api-extractor` package provides a Rollup plugin to seamlessly integrate `@microsoft/api-extractor` into TypeScript build workflows. It allows developers to generate and manage high-quality API declaration files (`.d.ts`) and API documentation reports directly within their Rollup build process. As of version 0.2.5, this plugin supports the latest features of API Extractor to enable consistent API surface definition and validation for libraries. It is actively maintained with relatively frequent minor updates since its initial release (0.2.2), making it a reliable choice for projects requiring robust type declaration bundling and API surface control. A key differentiator is its direct, configurable integration with Rollup, avoiding complex manual scripting for API Extractor execution.","status":"active","version":"0.2.5","language":"javascript","source_language":"en","source_url":"https://github.com/blacktau/rollup-plugin-api-extractor","tags":["javascript","rollup","plugin","typescript","api-extractor","@types"],"install":[{"cmd":"npm install rollup-plugin-api-extractor","lang":"bash","label":"npm"},{"cmd":"yarn add rollup-plugin-api-extractor","lang":"bash","label":"yarn"},{"cmd":"pnpm add rollup-plugin-api-extractor","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Runtime dependency for performing API extraction and declaration bundling.","package":"@microsoft/api-extractor","optional":false},{"reason":"Peer dependency as the plugin integrates directly with the Rollup build system.","package":"rollup","optional":false},{"reason":"Common TypeScript runtime library, often implicitly required by compiled TypeScript output.","package":"tslib","optional":true}],"imports":[{"note":"The `apiExtractor` function is a named export and must be imported using destructuring. This package is typically used in Rollup configuration files which usually support ESM syntax.","wrong":"import apiExtractor from 'rollup-plugin-api-extractor';","symbol":"apiExtractor","correct":"import { apiExtractor } from 'rollup-plugin-api-extractor';"},{"note":"For CommonJS environments (e.g., older Node.js Rollup configs), named exports are accessed via destructuring from the `require` call.","wrong":"const apiExtractor = require('rollup-plugin-api-extractor');","symbol":"apiExtractor (CJS)","correct":"const { apiExtractor } = require('rollup-plugin-api-extractor');"},{"note":"TypeScript users can import the `ApiExtractorPluginOptions` type for better type checking when configuring the plugin.","symbol":"Plugin Options Type","correct":"import { ApiExtractorPluginOptions } from 'rollup-plugin-api-extractor';"}],"quickstart":{"code":"import typescript from '@rollup/plugin-typescript';\nimport { apiExtractor } from 'rollup-plugin-api-extractor';\n\nexport default {\n  input: 'src/index.ts',\n  output: {\n    dir: 'dist',\n    format: 'esm'\n  },\n  plugins: [\n    typescript(),\n    apiExtractor({\n      // Optional: Specify a custom config file path if not at './config/api-extractor.json'\n      // configFile: './api-extractor.json'\n      // Optional: Override config settings directly\n      // configuration: {\n      //   mainEntryPointFilePath: '<projectFolder>/lib/index.d.ts'\n      // }\n    })\n  ]\n};","lang":"javascript","description":"This quickstart demonstrates integrating `rollup-plugin-api-extractor` into a basic Rollup configuration for a TypeScript project, bundling `src/index.ts` into ESM format and then processing declarations with API Extractor."},"warnings":[{"fix":"Run `npm install --save-dev @microsoft/api-extractor rollup` or `yarn add --dev @microsoft/api-extractor rollup`.","message":"`@microsoft/api-extractor` and `rollup` are peer dependencies of this plugin and must be installed separately in your project.","severity":"gotcha","affected_versions":">=0.2.2"},{"fix":"Ensure `tsconfig.json` includes: `{ \"compilerOptions\": { \"declaration\": true, \"declarationMap\": true } }`.","message":"For API Extractor to function correctly, your `tsconfig.json` must have `compilerOptions.declaration` and `compilerOptions.declarationMap` set to `true`.","severity":"gotcha","affected_versions":">=0.2.2"},{"fix":"Update `package.json`: `'types': 'path/to/your/main.d.ts'`.","message":"The `types` or `typings` field in your `package.json` must accurately point to the main declaration file (`.d.ts`) generated by API Extractor (e.g., `lib/index.d.ts`).","severity":"gotcha","affected_versions":">=0.2.2"},{"fix":"Run `npx api-extractor init` to generate the file, then edit `api-extractor.json` to set `'mainEntryPointFilePath': '<projectFolder>/lib/index.d.ts'` (adjust path as needed).","message":"The `api-extractor.json` configuration file must be initialized and its `mainEntryPointFilePath` property correctly configured to match your `package.json`'s `types` field.","severity":"gotcha","affected_versions":">=0.2.2"},{"fix":"Pass `{ configFile: './path/to/your/api-extractor.json' }` to the `apiExtractor()` plugin call in your `rollup.config.js`.","message":"If `api-extractor.json` is not located at the default path (`./config/api-extractor.json`), you must explicitly specify its path in the plugin options.","severity":"gotcha","affected_versions":">=0.2.2"}],"env_vars":null,"last_verified":"2026-04-22T00:00:00.000Z","next_check":"2026-07-21T00:00:00.000Z","problems":[{"fix":"Run `npx api-extractor init` to generate `api-extractor.json` in the default location (`config/`) or provide the correct path via the `configFile` plugin option: `apiExtractor({ configFile: './your-config.json' })`.","cause":"The `api-extractor.json` file is either missing, incorrectly named, or its path is not accessible/specified.","error":"Error: [@microsoft/api-extractor] The API Extractor configuration file could not be found."},{"fix":"Ensure you are using named import syntax: `import { apiExtractor } from 'rollup-plugin-api-extractor';` or for CommonJS: `const { apiExtractor } = require('rollup-plugin-api-extractor');`.","cause":"The plugin's named export `apiExtractor` was incorrectly imported as a default export or through an improper CommonJS `require` statement.","error":"TypeError: apiExtractor is not a function"},{"fix":"Install the missing peer dependencies using `npm install --save-dev rollup @microsoft/api-extractor` or `yarn add --dev rollup @microsoft/api-extractor`.","cause":"One or both of the required peer dependencies (`rollup` and `@microsoft/api-extractor`) are not installed in your project.","error":"You must install rollup (>=2.63.0) and @microsoft/api-extractor (>=7.19.0) as peer dependencies."}],"ecosystem":"npm"}