{"record":{"id":"58c23d6c788a9ade","repo":"sveltejs/kit","slug":"cloudflare-pages-routes-json-should-be-configure","errorCode":null,"errorMessage":"Cloudflare Pages' _routes.json should be configured from the adapter option of the SvelteKit plugin in your vite.config.js. See https://svelte.dev/docs/kit/adapter-cloudflare#Options-routes","messagePattern":"Cloudflare Pages' _routes\\.json should be configured from the adapter option of the SvelteKit plugin in your vite\\.config\\.js\\. See https://svelte\\.dev/docs/kit/adapter-cloudflare#Options-routes","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/adapter-cloudflare/index.js","lineNumber":33,"sourceCode":"} from './utils.js';\nimport { exactRegex } from '@rolldown/pluginutils';\nimport { getRequest } from '@sveltejs/kit/node';\n\nconst name = '@sveltejs/adapter-cloudflare';\n\n/** @type {typeof import('./index.js').default} */\nexport default function (options = {}) {\n\t// Add a random query so we can reliably string-replace the stub\n\tconst stub_import =\n\t\timport.meta.resolve('./src/virtual-cloudflare-workers.js') + '?' + crypto.randomUUID();\n\treturn {\n\t\tname,\n\t\tasync adapt(builder) {\n\t\t\tif (\n\t\t\t\tfs.existsSync('_routes.json') ||\n\t\t\t\tfs.existsSync(`${builder.config.files.assets}/_routes.json`)\n\t\t\t) {\n\t\t\t\tthrow new Error(\n\t\t\t\t\t\"Cloudflare Pages' _routes.json should be configured from the adapter option of the SvelteKit plugin in your vite.config.js. See https://svelte.dev/docs/kit/adapter-cloudflare#Options-routes\"\n\t\t\t\t);\n\t\t\t}\n\n\t\t\tif (fs.existsSync(`${builder.config.files.assets}/_headers`)) {\n\t\t\t\tthrow new Error(\n\t\t\t\t\t`The _headers file should be placed in the project root rather than the ${builder.config.files.assets} directory`\n\t\t\t\t);\n\t\t\t}\n\n\t\t\tif (fs.existsSync(`${builder.config.files.assets}/_redirects`)) {\n\t\t\t\tthrow new Error(\n\t\t\t\t\t`The _redirects file should be placed in the project root rather than the ${builder.config.files.assets} directory`\n\t\t\t\t);\n\t\t\t}\n\n\t\t\tconst { wrangler_config, building_for_cloudflare_pages } = validate_wrangler_config(\n\t\t\t\toptions.config","sourceCodeStart":15,"sourceCodeEnd":51,"githubUrl":"https://github.com/sveltejs/kit/blob/03f1687fe612ce3d2d9131139b5b188d9cf90c64/packages/adapter-cloudflare/index.js#L15-L51","documentation":"adapter-cloudflare generates _routes.json itself from the adapter's `routes` option. A hand-written _routes.json in the project root or in the assets directory conflicts with that generation and can silently break routing, so adapt() throws and points you at the SvelteKit plugin configuration instead.","triggerScenarios":"A _routes.json file exists in the project root or inside the configured assets directory (default `static/`) when running `vite build` with the Cloudflare adapter.","commonSituations":"Migrating a plain Cloudflare Pages project to SvelteKit and keeping the old _routes.json; copying Cloudflare docs examples that place _routes.json in static/.","solutions":["Delete the hand-written _routes.json from the project root and/or your static/assets directory.","Configure routing via the adapter option instead, e.g. adapter({ routes: { include: ['/*'], exclude: ['/static/*'] } }).","Re-run `vite build` so the adapter generates _routes.json from your option."],"exampleFix":"// vite.config.js before\nadapter({ routes: { include: ['/*'], exclude: ['<all>'] } });\n// and delete: static/_routes.json\n// after\nadapter({ routes: { include: ['/*'], exclude: ['/img/*', '/fonts/*'] } });","handlingStrategy":"validation","validationCode":"import fs from 'node:fs';\nif (fs.existsSync('_routes.json') || fs.existsSync('static/_routes.json')) {\n  throw new Error('Remove hand-written _routes.json; configure the adapter routes option instead');\n}","typeGuard":null,"tryCatchPattern":"try {\n  await viteBuild();\n} catch (err) {\n  if (/_routes.json should be configured from the adapter option/.test(err.message)) {\n    console.error('Delete _routes.json and move routing rules into the adapter routes option');\n  }\n  throw err;\n}","preventionTips":["Never commit _routes.json into the repo root or static/.","Express routing intent via the adapter's routes option in vite.config.js.","When migrating from plain Cloudflare Pages, remove legacy Pages config files first."],"tags":["cloudflare","configuration","build","adapter-cloudflare"],"backgroundTag":"routes-json-conflict","analyzedSha":"03f1687fe612ce3d2d9131139b5b188d9cf90c64","analyzedAt":"2026-09-02T02:01:50.504Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-09T06:17:21.866Z"}