sveltejs/kit · error · Error

routes.include must contain at least one route

Error message

routes.include must contain at least one route

What it means

Cloudflare limits the number of route include patterns in `_routes.json` (100 include rules for Workers with static assets). The adapter validates this at build time so deployment doesn't fail later at Cloudflare with an opaque error.

Source

Thrown at packages/adapter-cloudflare/utils.js:99

/**
 * Generates the [_routes.json](https://developers.cloudflare.com/pages/functions/routing/#create-a-_routesjson-file)
 * file that dictates which routes invoke the Cloudflare Worker.
 * @param {import('@sveltejs/kit').Builder} builder
 * @param {string[]} client_assets
 * @param {string[]} redirects
 * @param {import('./index.js').AdapterOptions['routes']} routes
 * @returns {import('./index.js').RoutesJSONSpec}
 */
export function get_routes_json(builder, client_assets, redirects, routes) {
	const include = routes?.include ?? ['/*'];
	let exclude = routes?.exclude ?? ['<all>'];

	if (!Array.isArray(include) || !Array.isArray(exclude)) {
		throw new Error('routes.include and routes.exclude must be arrays');
	}

	if (include?.length === 0) {
		throw new Error('routes.include must contain at least one route');
	}

	if (include?.length > 100) {
		throw new Error('routes.include must contain 100 or fewer routes');
	}

	/** @type {Set<string>} */
	const transformed_rules = new Set();
	for (const rule of exclude) {
		if (rule === '<all>') {
			transformed_rules.add('<build>');
			transformed_rules.add('<files>');
			transformed_rules.add('<prerendered>');
			transformed_rules.add('<redirects>');
		} else {
			transformed_rules.add(rule);
		}
	}

View on GitHub (pinned to 03f1687fe6)

Solutions

  1. Consolidate patterns with wildcards, e.g. ['/api/*'] instead of listing every endpoint.
  2. Invert the logic: use exclude patterns for the minority of paths instead of enumerating includes.
  3. Trim the include list to under 100 entries, prioritizing the highest-traffic routes.
  4. If genuinely more than 100 distinct patterns are needed, reconsider using _routes.json and handle routing inside the Worker.

Example fix

// before
routes: { include: ['/a', '/b', '/c', /* ...150 paths */] }

// after
routes: { include: ['/api/*'], exclude: ['/static/*', '/favicon.ico'] }
Defensive patterns

Strategy: validation

Validate before calling

const include = routes?.include ?? ['/*'];
if (include.length > 100) {
  throw new Error('routes.include must contain 100 or fewer routes');
}

Type guard

function withinRouteLimit(include) {
  return Array.isArray(include) && include.length <= 100;
}

Try / catch

try {
  await viteBuild();
} catch (e) {
  if (String(e).includes('100 or fewer routes')) {
    console.error('Consolidate routes.include patterns with wildcards');
    process.exit(1);
  }
  throw e;
}

Prevention

When it happens

Trigger: Providing an adapter `routes.include` array with more than 100 entries during adapt/get_routes_json (e.g. enumerating hundreds of individual paths).

Common situations: Excluding many API endpoints by listing each path individually instead of using wildcards; auto-generated route lists from a CMS with many top-level paths.

Related errors


AI-assisted analysis of sveltejs/kit@03f1687fe6 (2026-09-02). Data as JSON: /api/errors/5929afa74155a2a8. Report an issue: GitHub.