Kubb Troubleshooting Guide
Solve common Kubb issues quickly with this comprehensive troubleshooting guide. Find solutions for installation problems, configuration errors, generation failures, and runtime issues.
How to Use This Guide
- Identify your issue - Find the category that matches your problem
- Try the solution - Follow the recommended fix
- Enable debug mode - If the issue persists, use debug mode for detailed logs
- Get help - Join Discord or create a GitHub issue if you're still stuck
Installation Issues
Node.js Version Error
Error: Kubb requires Node.js 20 or higher
Solution: Update your Node.js version to 20 or higher.
# Check your Node.js version
node --version
# Update using nvm
nvm install 20
nvm use 20Package Manager Conflicts
Error: Package installation fails with peer dependency errors
Solution: Clear your package manager cache and reinstall:
bun pm cache rm
rm -rf node_modules bun.lockb
bun installpnpm store prune
rm -rf node_modules pnpm-lock.yaml
pnpm installnpm cache clean --force
rm -rf node_modules package-lock.json
npm installyarn cache clean
rm -rf node_modules yarn.lock
yarn installConfiguration Issues
Config File Not Found
Error: Cannot find kubb config file
Solution: Ensure your config file exists in the project root with one of these names:
kubb.config.ts- TypeScript (recommended)kubb.config.js- JavaScript (requires"type": "module"inpackage.json)kubb.config.mjs- ESM JavaScriptkubb.config.cjs- CommonJS JavaScript
Specify a custom config path:
kubb generate --config ./configs/kubb.config.tsInvalid OpenAPI File
Error: Failed to parse OpenAPI specification
Solution:
- Validate your OpenAPI file using the Swagger Editor
- Ensure the file path is correct in your config
- If using a URL, verify it's accessible
import { defineConfig } from '@kubb/core'
export default defineConfig({
input: {
// Use absolute path if relative path fails
path: './petStore.yaml',
},
output: {
path: './src/gen',
},
})Module Type Errors
Error: Cannot use import statement outside a module
Solution: Ensure you have "type": "module" in your package.json, or rename your config file to use the .mjs extension.
{
"type": "module"
}Generation Issues
Missing Plugin Dependencies
Error: Plugin X requires plugin Y to be installed
Solution: Install the required dependency plugin. Check the plugin documentation for its prerequisites.
Most plugins require @kubb/plugin-oas:
import { defineConfig } from '@kubb/core'
import { pluginOas } from '@kubb/plugin-oas'
import { pluginTs } from '@kubb/plugin-ts'
export default defineConfig({
input: { path: './petStore.yaml' },
output: { path: './src/gen' },
plugins: [
pluginOas(), // Required by most plugins
pluginTs(),
],
})Empty or Incomplete Output
Problem: Generated files are empty or missing content
Solutions:
- Check if your OpenAPI file has the expected paths/schemas
- Review the
include/excludeoptions in your plugin config - Enable debug mode to see what's happening:
kubb generate --debugType Generation Errors
Error: TypeScript errors in generated files
Solutions:
- Check your
tsconfig.jsoncompiler options - Ensure
moduleResolutionis set tobundlerornode16 - Verify the
pathsmapping if using path aliases
{
"compilerOptions": {
"moduleResolution": "bundler",
"esModuleInterop": true,
"strict": true
}
}Performance Issues
Slow Generation
Problem: Code generation takes a long time
Solutions:
- Use the
includeoption to generate only what you need:
pluginTs({
include: [
{ type: 'tag', pattern: 'pets' },
],
})- Disable unused plugins
- Use a smaller OpenAPI specification for development
Out of Memory
Error: JavaScript heap out of memory
Solution: Increase Node.js memory limit. Adjust the value based on available system memory (4096 = 4GB):
NODE_OPTIONS="--max-old-space-size=4096" kubb generateRuntime Issues
Import Errors
Error: Cannot find module when importing generated code
Solutions:
- Verify the output path matches your import path
- Check the
output.extensionoption:
export default defineConfig({
output: {
path: './src/gen',
extension: {
'.ts': '.js', // For ESM compatibility
},
},
})- Ensure barrel files are generated (check
output.barrelType)
Client Request Errors
Problem: Generated API clients fail to make requests
Solutions:
- Verify your base URL configuration:
import { client } from './gen/client'
client.setConfig({
baseURL: 'https://api.example.com',
})- Check if CORS is enabled on the server
- Verify authentication headers are set correctly
Debug Mode
Enable debug mode to get detailed logs:
kubb generate --debugThis creates log files in the .kubb directory (e.g., .kubb/kubb-{name}-{timestamp}.log). The CLI displays the exact location of each debug log file after generation completes.
Getting Help
If you're still experiencing issues:
- Check the GitHub Issues for similar problems
- Join the Discord community for help
- Create a new issue with:
- Kubb version
- Node.js version
- Minimal reproduction steps
- Error messages and logs
FAQ
Can I use Kubb with JavaScript instead of TypeScript?
Yes, Kubb generates TypeScript by default, but you can use the output in JavaScript projects. The generated .ts files can be transpiled to JavaScript using your build tool.
How do I update generated code when my OpenAPI spec changes?
Simply re-run kubb generate. Use the output.clean option to remove old files:
output: {
path: './src/gen',
clean: true, // Removes old files before generating
}Can I customize the generated code?
Yes, you can use:
- Generators: Create custom generators to control output
- Transformers: Modify names and paths
- Override: Override generation for specific operations/schemas
See Generators for more details.
