or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

docs

configuration.mdindex.mdutilities.md
tile.json

tessl/npm-sveltejs--adapter-vercel

A SvelteKit adapter that creates a Vercel app

Workspace
tessl
Visibility
Public
Created
Last updated
Describes
npmpkg:npm/@sveltejs/adapter-vercel@5.10.x

To install, run

npx @tessl/cli install tessl/npm-sveltejs--adapter-vercel@5.10.0

index.mddocs/

SvelteKit Adapter for Vercel

The 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).

Package Information

  • Package Name: @sveltejs/adapter-vercel
  • Package Type: npm
  • Language: JavaScript/TypeScript
  • Installation: npm install @sveltejs/adapter-vercel

Core Imports

import adapter from "@sveltejs/adapter-vercel";

For CommonJS:

const adapter = require("@sveltejs/adapter-vercel");

Basic Usage

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
    })
  }
};

Architecture

The adapter transforms SvelteKit applications for Vercel deployment by:

  • Build Transformation: Converts SvelteKit output into Vercel Build Output API format
  • Function Generation: Creates serverless or edge functions based on configuration
  • Static Asset Handling: Optimizes and deploys static assets with proper caching headers
  • Route Configuration: Maps SvelteKit routes to Vercel's routing system
  • Bundle Optimization: Uses Vercel's Node File Trace (NFT) for minimal bundle sizes

Capabilities

Main Adapter Function

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;
  };
}

Adapter Configuration

Configuration Types

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';

Configuration Reference

Utility Functions

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;
}

Utilities

Runtime Detection and Error Handling

The adapter automatically detects and validates runtime environments to ensure compatibility:

Automatic Runtime Detection

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:

  • Uses the Node.js version from the build environment
  • Only supports even-numbered Node.js versions (18, 20, 22, etc.)
  • Validates version compatibility with Vercel platform

Common Validation Errors

The adapter performs several validation checks and provides helpful error messages:

1. Unsupported Node.js Version

// ❌ 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"

2. Legacy Edge Configuration

// ❌ Error: Using deprecated edge syntax
adapter({ edge: true });
// Error: "{ edge: true } has been removed in favour of { runtime: 'edge' }"

3. SvelteKit Version Compatibility

// ❌ Error: Using adapter-vercel 2.x+ with old SvelteKit
// Error: "@sveltejs/adapter-vercel >=2.x requires @sveltejs/kit version 1.5 or higher"

4. Runtime-Specific Feature Conflicts

// ❌ 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')"

Troubleshooting Guide

Build Environment Issues:

  • Ensure you're using an even-numbered Node.js version (18, 20, 22)
  • Update your local Node.js version to match supported versions
  • Check your CI/CD environment's Node.js configuration

Runtime Configuration:

  • Use nodejs20.x instead of deprecated edge runtime for new projects
  • Specify explicit runtime if automatic detection fails
  • Ensure ISR features only use Node.js runtimes

Version Compatibility:

  • Update @sveltejs/kit to version 1.5 or higher for adapter-vercel 2.x+
  • Check peer dependency requirements in package.json