sveltejs/kit · error · Error
Invalid export '${key}'${file ? ` in ${file}` : ''} (${hint}
Error message
Invalid export '${key}'${file ? ` in ${file}` : ''} (${hint}) What it means
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.
Source
Thrown at packages/kit/src/utils/exports.js:21
*/
function validator(expected) {
/**
* @param {any} module
* @param {string} [file]
*/
function validate(module, file) {
if (!module) return;
for (const key in module) {
if (key[0] === '_' || expected.has(key)) continue; // key is valid in this module
const values = [...expected.values()];
const hint =
hint_for_supported_files(key, file?.slice(file.lastIndexOf('.'))) ??
`valid exports are ${values.join(', ')}, or anything with a '_' prefix`;
throw new Error(`Invalid export '${key}'${file ? ` in ${file}` : ''} (${hint})`);
}
}
return validate;
}
/**
* @param {string} key
* @param {string} ext
* @returns {string | void}
*/
function hint_for_supported_files(key, ext = '.js') {
const supported_files = [];
if (valid_layout_exports.has(key)) {
supported_files.push(`+layout${ext}`);
}
View on GitHub (pinned to 03f1687fe6)
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
Example fix
// before: +page.js
export const actions = { default: () => ({}) };
// after: +page.server.js
export const actions = { default: async ({ request }) => ({ success: true }) }; Defensive patterns
Strategy: validation
Validate before calling
const VALID = new Set(['load','prerender','csr','ssr','trailingSlash','config','actions','entries','GET','POST','PATCH','PUT','DELETE','OPTIONS','HEAD','fallback']);
export const checkExports = (mod) => Object.keys(mod).filter((k) => !k.startsWith('_') && !VALID.has(k)); Type guard
const hasOnlyValidExports = (mod, valid) =>
Object.keys(mod ?? {}).every((k) => k.startsWith('_') || valid.includes(k)); Try / catch
// This error is thrown at build/dev time; there is no runtime catch.
// Defend in CI by validating route modules before build:
try {
await import('./src/routes/+page.js');
} catch (e) {
if (e.message.startsWith('Invalid export')) process.exit(1);
} Prevention
- 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
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- ${keypath} cannot be empty
- Each member of ${keypath} must start with '.' — saw '${exten
- ${keypath} should be one of "${options}" or "${options[optio
- Invalid character escape sequence in ${id}
- Hexadecimal escape sequence in ${id} must be two characters
AI-assisted analysis of sveltejs/kit@03f1687fe6 (2026-09-02).
Data as JSON: /api/errors/d44ebe169d75bced.
Report an issue: GitHub.