sveltejs/kit · error · Error
`${name}` exported from ${file} is invalid — all exports fro
Error message
`${name}` exported from ${file} is invalid — all exports from this file must be remote functions What it means
Every export from a remote module must be a valid remote function (its `__` metadata type must be one of the known remote-function types). Any plain value, class, or arbitrary function export is rejected because SvelteKit needs to stamp each export with a stable id and name for RPC.
Source
Thrown at packages/kit/src/exports/internal/server/remote-functions.js:20
/** @type {RemoteInternals['type'][]} */
const types = ['command', 'form', 'prerender', 'query', 'query_batch', 'query_live'];
/**
* @param {Record<string, any>} module
* @param {string} file
* @param {string} hash
*/
export function init_remote_functions(module, file, hash) {
if (module.default) {
throw new Error(
`Cannot export \`default\` from a remote module (${file}) — please use named exports instead`
);
}
for (const [name, fn] of Object.entries(module)) {
if (!types.includes(fn?.__?.type)) {
throw new Error(
`\`${name}\` exported from ${file} is invalid — all exports from this file must be remote functions`
);
}
fn.__.id = `${hash}/${name}`;
fn.__.name = name;
}
}
View on GitHub (pinned to 03f1687fe6)
Solutions
- Remove non-remote exports from the remote module and move them to a regular module.
- Wrap every exported function in the appropriate remote primitive (`query`, `command`, `form`, etc.).
- Check that the export is not undefined due to a bad import (the wrapper was never called).
Example fix
// before export const LIMIT = 10; export const getPosts = () => db.posts.all(); // after export const getPosts = query(() => db.posts.limit(10).all());
Defensive patterns
Strategy: validation
Validate before calling
// every export must carry remote-function metadata
for (const [name, fn] of Object.entries(mod)) {
if (!fn?.__?.type) throw new Error(`${name} in remote module is not a remote function`);
} Type guard
const isRemoteFunction = (v) => typeof v === 'function' && v?.__ && typeof v.__.type === 'string';
Try / catch
try {
init(mod);
} catch (e) {
if (String(e.message).includes('is invalid — all exports')) {
console.error('Move non-remote exports out of the remote module:', e.message);
} else throw e;
} Prevention
- Wrap every exported function in query()/command()/form().
- Keep constants/types/helpers in regular modules, not remote files.
- Check for typos that make the wrapper's result undefined.
When it happens
Trigger: Exporting a plain constant (`export const API_KEY = 'x'`), a helper function, or a class from a `.remote.ts` file; exporting something created by a function that forgot to wrap it in `query`/`command`/`form` etc.
Common situations: Sharing types/constants alongside remote functions in the same file; accidentally importing and re-exporting a non-remote helper; forgetting the `query(...)`/`command(...)` wrapper so the raw function lacks `__` metadata.
Related errors
- Cannot export `default` from a remote module (${file}) — ple
- Could not get the request store.
- A form object can only be attached to a single `<form>` elem
- Updates can only be sent once per command invocation. Ignori
- ${message}\n\n${summary}\n\n${suggestion}
AI-assisted analysis of sveltejs/kit@03f1687fe6 (2026-09-02).
Data as JSON: /api/errors/d09da06955b967c4.
Report an issue: GitHub.