Skip to content

Plugin Dependencies

Most of Shokupan’s dependencies are now optional peer dependencies. This means:

  • ✅ Smaller install size for basic apps
  • ✅ Install only what you use
  • ✅ Clear error messages when dependencies are missing
  • ✅ Better tree-shaking and bundle optimization

Packages: class-transformer, class-validator, reflect-metadata

Terminal window
bun add class-transformer class-validator reflect-metadata

Usage:

import { validate } from 'shokupan';
import { IsString, IsNumber } from 'class-validator';
class CreateUserDto {
@IsString()
name: string;
@IsNumber()
age: number;
}
app.post('/users', validate({ body: CreateUserDto }), async (ctx) => {
const user = await ctx.body(); // Validated and transformed
return ctx.json({ user });
});

Packages: arctic, jose

Terminal window
bun add arctic jose

Usage:

import { AuthPlugin } from 'shokupan';
const auth = new AuthPlugin({
jwtSecret: process.env.JWT_SECRET,
providers: {
github: {
clientId: process.env.GITHUB_CLIENT_ID,
clientSecret: process.env.GITHUB_CLIENT_SECRET,
redirectUri: 'http://localhost:3000/auth/github/callback'
}
}
});
app.mount('/auth', auth);

Packages: ajv, ajv-formats

Terminal window
bun add ajv ajv-formats

Usage:

import { enableOpenApiValidation } from 'shokupan';
const app = new Shokupan({ enableOpenApiGen: true });
// Add routes...
enableOpenApiValidation(app); // Validates requests against OpenAPI spec

Packages: @scalar/api-reference, eta

Terminal window
bun add @scalar/api-reference eta

Usage:

import { mountScalar } from 'shokupan';
const app = new Shokupan({ enableOpenApiGen: true });
// Add routes...
mountScalar(app, '/docs', {
title: 'My API Documentation'
});

Packages: eta

Terminal window
bun add eta

Usage:

import { serveStatic } from 'shokupan';
app.mount('/static', serveStatic({
root: './public',
listDirectory: true
}));

Packages: parse-json, secure-json-parse

Terminal window
# For better error messages
bun add parse-json
# For security against prototype pollution
bun add secure-json-parse

Usage:

const app = new Shokupan({
jsonParser: 'parse-json' // or 'secure-json-parse' or 'native'
});

These are always installed and required for core functionality:

PackagePurpose
@scalar/openapi-typesTypeScript types for OpenAPI
@opentelemetry/*Optional tracing support
@surrealdb/nodeSession storage backend
tslibTypeScript runtime helpers

When you try to use a plugin without its dependencies installed, you’ll get a clear error message:

Error: class-transformer and class-validator are required for class-based validation.
Install them with: bun add class-transformer class-validator reflect-metadata

If you’re upgrading from an earlier version where all dependencies were bundled:

Check your code for imports from:

  • validation.ts → needs class-validator packages
  • auth.ts / AuthPlugin → needs arctic, jose
  • openapi-validator.ts → needs ajv packages
  • serveStatic / mountScalar → needs eta
  • @scalar/api-reference → needs @scalar/api-reference
Terminal window
# Example: If you use validation and auth
bun add class-transformer class-validator reflect-metadata arctic jose

Your existing code will continue to work. The only difference is you need to install the dependencies explicitly.

Install all optional dependencies for development:

Terminal window
bun add -d class-transformer class-validator reflect-metadata \
arctic jose ajv ajv-formats @scalar/api-reference eta \
parse-json secure-json-parse

Install only what you use:

Terminal window
# Example: Auth-only API
bun add arctic jose
# Example: Validated REST API with docs
bun add class-transformer class-validator reflect-metadata \
@scalar/api-reference eta

Approximate package sizes (minified + gzipped):

PackageSizePurpose
class-validator~50KBValidation decorators
class-transformer~20KBObject transformation
arctic~30KBOAuth providers
jose~25KBJWT operations
ajv~45KBJSON Schema validation
@scalar/api-reference~200KBAPI documentation UI
eta~5KBTemplate engine

Total if using all: ~375KB
Core framework only: ~50KB

By installing only what you need, you can significantly reduce your bundle size!

Solution: Install the missing package shown in the error message.

If using class-validator, ensure you have:

  1. Installed reflect-metadata
  2. Imported it at the top of your entry file:
    import 'reflect-metadata';

Ensure you have the type definitions installed:

Terminal window
bun add -d @types/node