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
- Consolidate patterns with wildcards, e.g. ['/api/*'] instead of listing every endpoint.
- Invert the logic: use exclude patterns for the minority of paths instead of enumerating includes.
- Trim the include list to under 100 entries, prioritizing the highest-traffic routes.
- 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
- Prefer wildcard patterns like ['/api/*'] over enumerating paths.
- Count routes.include entries in CI before building.
- Use exclude patterns for minority-path exclusion instead of many includes.
- Revisit routing strategy if you legitimately need more than 100 patterns.
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
- The following _redirects rule cannot be excluded by _routes.
- routes.include and routes.exclude must be arrays
- You must remove all `site` keys in ${config_path}. Consult h
- You must specify the `assets.directory` key in ${config_path
- You must specify the `assets.binding` key in ${config_path}
AI-assisted analysis of sveltejs/kit@03f1687fe6 (2026-09-02).
Data as JSON: /api/errors/5929afa74155a2a8.
Report an issue: GitHub.