unplugin-kubb
raw JSON → 5.0.16 verified Mon Apr 27 auth: no javascript
Universal build plugin for Kubb that integrates OpenAPI code generation into Vite, Webpack, Rollup, esbuild, Rspack, Nuxt, and Astro build processes. Current stable version is 5.0.16, with alpha releases signaling active development. It ships TypeScript types and requires Node >=20. Key differentiators: multi-bundler support via unplugin, seamless integration with modern build tools, and automatic code generation from OpenAPI specs.
Common errors
error Cannot find module 'unplugin-kubb' or its corresponding type declarations. ↓
cause Package not installed or missing TypeScript declaration.
fix
Run
npm install unplugin-kubb @kubb/core and ensure tsconfig includes node_modules. error TypeError: KubbPlugin is not a function ↓
cause Using default import with require() or wrong import statement.
fix
Use
import KubbPlugin from 'unplugin-kubb' (ESM). error Error [ERR_REQUIRE_ESM]: require() of ES Module ... not supported. ↓
cause CommonJS require() used with ESM-only package.
fix
Switch to
import syntax or use dynamic import(). error Uncaught TypeError: Cannot read properties of undefined (reading 'path') ↓
cause Missing or incorrectly configured `input` option.
fix
Provide
input object with path or url property. Warnings
breaking ESM-only since v5: CommonJS require() not supported. ↓
fix Switch to ESM imports and set `"type": "module"` in package.json.
breaking Minimum Node version raised to 20 in v5. ↓
fix Upgrade Node.js to >=20.
gotcha Plugin must be placed before other plugins that transform output files. ↓
fix Place KubbPlugin early in the plugins array to ensure generated files are available.
gotcha Dependency on @kubb/core version ^4.0.0 may cause peer dependency conflicts if using Kubb v5 alpha. ↓
fix Ensure all Kubb packages are on the same version range.
deprecated The `input` option `path` is deprecated in favor of `input.url` in v5 alpha. ↓
fix Use `input.url` instead of `input.path`.
Install
npm install unplugin-kubb yarn add unplugin-kubb pnpm add unplugin-kubb Imports
- KubbPlugin wrong
const { KubbPlugin } = require('unplugin-kubb')correctimport { KubbPlugin } from 'unplugin-kubb' - default wrong
const KubbPlugin = require('unplugin-kubb')correctimport KubbPlugin from 'unplugin-kubb' - type KubbPluginOptions
import type { KubbPluginOptions } from 'unplugin-kubb' - createKubbPlugin wrong
import { CreateKubbPlugin } from 'unplugin-kubb'correctimport { createKubbPlugin } from 'unplugin-kubb'
Quickstart
import { defineConfig } from 'vite';
import KubbPlugin from 'unplugin-kubb';
export default defineConfig({
plugins: [
KubbPlugin({
input: {
path: './openapi.yaml',
},
output: {
path: './src/generated',
},
// Optional: specify additional plugins
plugins: ['@kubb/swagger-ts', '@kubb/swagger-client'],
}),
],
});