{"record":{"id":"d44ebe169d75bced","repo":"sveltejs/kit","slug":"invalid-export-key-file-in-file","errorCode":null,"errorMessage":"Invalid export '${key}'${file ? ` in ${file}` : ''} (${hint})","messagePattern":"Invalid export '(.+?)'(.+?)` : ''\\} \\((.+?)\\)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/kit/src/utils/exports.js","lineNumber":21,"sourceCode":" */\nfunction validator(expected) {\n\t/**\n\t * @param {any} module\n\t * @param {string} [file]\n\t */\n\tfunction validate(module, file) {\n\t\tif (!module) return;\n\n\t\tfor (const key in module) {\n\t\t\tif (key[0] === '_' || expected.has(key)) continue; // key is valid in this module\n\n\t\t\tconst values = [...expected.values()];\n\n\t\t\tconst hint =\n\t\t\t\thint_for_supported_files(key, file?.slice(file.lastIndexOf('.'))) ??\n\t\t\t\t`valid exports are ${values.join(', ')}, or anything with a '_' prefix`;\n\n\t\t\tthrow new Error(`Invalid export '${key}'${file ? ` in ${file}` : ''} (${hint})`);\n\t\t}\n\t}\n\n\treturn validate;\n}\n\n/**\n * @param {string} key\n * @param {string} ext\n * @returns {string | void}\n */\nfunction hint_for_supported_files(key, ext = '.js') {\n\tconst supported_files = [];\n\n\tif (valid_layout_exports.has(key)) {\n\t\tsupported_files.push(`+layout${ext}`);\n\t}\n","sourceCodeStart":3,"sourceCodeEnd":39,"githubUrl":"https://github.com/sveltejs/kit/blob/03f1687fe612ce3d2d9131139b5b188d9cf90c64/packages/kit/src/utils/exports.js#L3-L39","documentation":"SvelteKit validates that special route modules (+page, +layout, +page.server, +layout.server, +server) only export known keys; anything prefixed with '_' is allowed as a private helper. Exporting an unrecognized name causes the build/dev to fail with this error, including a hint that often points to the correct file type for that export.","triggerScenarios":"Exporting an action/load-only name from the wrong module (e.g. `actions` in +layout.js, `GET` in +page.js); typos like `export const prerender = truee`; exporting helper functions without an '_' prefix; leftover exports from renamed Kit APIs.","commonSituations":"Moving code between +page.server.js and +page.js; copy-pasting route files; typos in config exports like `ssr`, `csr`, `trailingSlash`; exporting non-route utilities from route files.","solutions":["Move the export to the file type shown in the hint (e.g. `actions` belongs in +page.server.js)","Prefix genuinely private helpers with '_' (e.g. `export const _helper = ...`) or move them out of the route file","Fix typos in standard exports (`prerender`, `csr`, `ssr`, `trailingSlash`, `config`)","Check the Kit version's valid export list — APIs like `entries` only exist in newer versions"],"exampleFix":"// before: +page.js\nexport const actions = { default: () => ({}) };\n// after: +page.server.js\nexport const actions = { default: async ({ request }) => ({ success: true }) };","handlingStrategy":"validation","validationCode":"const VALID = new Set(['load','prerender','csr','ssr','trailingSlash','config','actions','entries','GET','POST','PATCH','PUT','DELETE','OPTIONS','HEAD','fallback']);\nexport const checkExports = (mod) => Object.keys(mod).filter((k) => !k.startsWith('_') && !VALID.has(k));","typeGuard":"const hasOnlyValidExports = (mod, valid) =>\n  Object.keys(mod ?? {}).every((k) => k.startsWith('_') || valid.includes(k));","tryCatchPattern":"// This error is thrown at build/dev time; there is no runtime catch.\n// Defend in CI by validating route modules before build:\ntry {\n  await import('./src/routes/+page.js');\n} catch (e) {\n  if (e.message.startsWith('Invalid export')) process.exit(1);\n}","preventionTips":["Only export documented keys from +page/+layout/+server files","Prefix private helpers with '_' or move them to $lib","Copy standard option blocks (prerender/csr/ssr) rather than retyping them","Let the error's hint tell you which file type supports the export"],"tags":["sveltekit","routes","validation","build"],"backgroundTag":"invalid-route-module-export","analyzedSha":"03f1687fe612ce3d2d9131139b5b188d9cf90c64","analyzedAt":"2026-09-02T02:01:50.504Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-09T06:17:21.866Z"}