A SvelteKit adapter that creates a Vercel app
npx @tessl/cli install tessl/npm-sveltejs--adapter-vercel@5.10.0The SvelteKit Adapter for Vercel enables seamless deployment of SvelteKit applications to the Vercel platform. It handles build process transformation, serverless function generation, and static asset optimization required for Vercel's deployment infrastructure, with automatic configuration for serverless architecture, edge functions, and ISR (Incremental Static Regeneration).
npm install @sveltejs/adapter-vercelimport adapter from "@sveltejs/adapter-vercel";For CommonJS:
const adapter = require("@sveltejs/adapter-vercel");Configure the adapter in your svelte.config.js:
import adapter from "@sveltejs/adapter-vercel";
export default {
kit: {
adapter: adapter()
}
};With configuration options:
import adapter from "@sveltejs/adapter-vercel";
export default {
kit: {
adapter: adapter({
runtime: "nodejs20.x",
regions: ["iad1"],
memory: 512,
maxDuration: 30
})
}
};The adapter transforms SvelteKit applications for Vercel deployment by:
Primary adapter factory function that creates a Vercel adapter instance for SvelteKit configuration.
function adapter(config?: Config): Adapter;
// Main configuration type
type Config = (EdgeConfig | ServerlessConfig) & {
images?: ImagesConfig;
};
// Adapter type from @sveltejs/kit
interface Adapter {
name: string;
adapt(builder: any): Promise<void>;
supports?: {
read?: ({ config, route }: { config: any; route: any }) => boolean;
instrumentation?: () => boolean;
};
}Type definitions for adapter configuration including serverless, edge, and image optimization settings.
interface ServerlessConfig {
runtime?: `nodejs${number}.x`;
regions?: string[];
maxDuration?: number;
memory?: number;
split?: boolean;
isr?: {
expiration: number | false;
bypassToken?: string;
allowQuery?: string[] | undefined;
} | false;
}
/**
* @deprecated Edge runtime configuration is deprecated
* Will be removed in a future version of adapter-vercel
*/
interface EdgeConfig {
runtime?: 'edge';
regions?: string[] | 'all';
external?: string[];
split?: boolean;
}
interface ImagesConfig {
sizes: number[];
domains: string[];
remotePatterns?: RemotePattern[];
minimumCacheTTL?: number;
formats?: ImageFormat[];
dangerouslyAllowSVG?: boolean;
contentSecurityPolicy?: string;
contentDispositionType?: string;
}
interface RemotePattern {
protocol?: 'http' | 'https';
hostname: string;
port?: string;
pathname?: string;
}
type ImageFormat = 'image/avif' | 'image/webp';Helper functions for route processing and pattern conversion used internally by the adapter.
function get_pathname(route: RouteDefinition<any>): string;
function pattern_to_src(pattern: string): string;
// Route definition type from @sveltejs/kit
interface RouteDefinition<Config = any> {
id: string;
pattern: RegExp;
segments: Array<{
content: string;
dynamic: boolean;
rest: boolean;
}>;
methods: string[];
prerender?: boolean | 'auto';
config?: Config;
}The adapter automatically detects and validates runtime environments to ensure compatibility:
When no runtime is specified, the adapter automatically selects the appropriate Node.js runtime:
// Automatic runtime detection based on build environment
adapter(); // Uses build environment's Node.js version
// Equivalent to:
adapter({
runtime: "nodejs20.x" // (example - actual version depends on build env)
});Detection Logic:
The adapter performs several validation checks and provides helpful error messages:
// ❌ Error: Building with Node.js 17 (odd version)
// Error: "Unsupported Node.js version: v17.x.x. Please use an even-numbered Node version"
// ❌ Error: Building with Node.js 16 (too old)
// Error: "Building locally with unsupported Node.js version: v16.x.x. Please use Node 18, 20 or 22"// ❌ Error: Using deprecated edge syntax
adapter({ edge: true });
// Error: "{ edge: true } has been removed in favour of { runtime: 'edge' }"// ❌ Error: Using adapter-vercel 2.x+ with old SvelteKit
// Error: "@sveltejs/adapter-vercel >=2.x requires @sveltejs/kit version 1.5 or higher"// ❌ Error: ISR with edge runtime
adapter({
runtime: "edge",
isr: { expiration: 300 }
});
// Error: "Routes using `isr` must use a Node.js runtime (for example 'nodejs20.x')"Build Environment Issues:
Runtime Configuration:
nodejs20.x instead of deprecated edge runtime for new projectsVersion Compatibility:
@sveltejs/kit to version 1.5 or higher for adapter-vercel 2.x+