sveltejs/kit · error · Error
routes.include must contain 100 or fewer routes
Error message
routes.include must contain 100 or fewer routes
What it means
Cloudflare Pages limits _routes.json to at most 100 include rules. The adapter enforces this limit at build time, throwing when routes.include has more than 100 patterns, because the deploy would be rejected by Cloudflare.
Source
Thrown at packages/adapter-cloudflare/utils.js:103
* @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);
}
}
/** @type {Set<string>} */
const excluded_routes = new Set();
for (const rule of transformed_rules) {View on GitHub (pinned to 03f1687fe6)
Solutions
- Consolidate patterns with wildcards, e.g. replace many /api/x rules with '/api/*'
- Invert the logic: use a broad include like ['/*'] and move excess entries into exclude
- Prerender pages that don't need the server function so they can be excluded with fewer rules
Example fix
// before
adapter({ routes: { include: ['/a','/b','/c', /* ...150 rules */] } })
// after
adapter({ routes: { include: ['/a/*','/b/*'], exclude: ['<all>'] } }) Defensive patterns
Strategy: validation
Validate before calling
const include = routes?.include ?? ['/*'];
if (Array.isArray(include) && include.length > 100) {
throw new RangeError(`routes.include has ${include.length} rules; Cloudflare allows at most 100`);
} Type guard
const withinLimit = (r) => (r?.include ?? ['/*']).length <= 100;
Try / catch
try {
await vite.build();
} catch (e) {
if (e.message.includes('100 or fewer routes')) {
console.error('Consolidate routes.include patterns using wildcards');
}
throw e;
} Prevention
- Check include length in CI before deploying to Cloudflare Pages
- Prefer wildcard patterns like '/api/*' over one rule per path
- Keep the include list broad and push exceptions into exclude
When it happens
Trigger: Passing routes.include with more than 100 pattern strings to adapter-cloudflare in svelte.config.js, e.g. a programmatically generated list of 150 route patterns.
Common situations: Large apps auto-generating an include rule per dynamic route; teams mirroring an old catch-all-plus-exceptions setup that grew over 100 entries.
Related errors
- routes.include must contain at least one route
- read(...) failed: could not fetch ${url} (${response.status}
- Cloudflare Pages' _routes.json should be configured from the
- The _headers file should be placed in the project root rathe
- The _redirects file should be placed in the project root rat
AI-assisted analysis of sveltejs/kit@03f1687fe6 (2026-09-02).
Data as JSON: /api/errors/b80f276fe7e673c3.
Report an issue: GitHub.