sveltejs/kit · error · Error

Cannot export `default` from a remote module (${file}) — ple

Error message

Cannot export `default` from a remote module (${file}) — please use named exports instead

What it means

Remote (`*.remote.js/ts`) modules may only export remote functions (queries, commands, etc.). A `default` export is rejected at init time because remote function identity is derived from named exports plus the module hash, and default exports have no stable name.

Source

Thrown at packages/kit/src/exports/internal/server/remote-functions.js:13

/** @import { RemoteInternals } from 'types' */

/** @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

  1. Remove the `export default` from the remote module.
  2. Re-export each remote function by name: `export const q = query(...)`.
  3. If a shared default object is needed, keep it in a separate non-remote module and import it into the remote file.

Example fix

// before
export default query('getPosts', () => db.posts.all());
// after
export const getPosts = query(() => db.posts.all());
Defensive patterns

Strategy: validation

Validate before calling

// lint-level check before building
const remoteFiles = await glob('src/**/*.remote.{js,ts}');
for (const f of remoteFiles) {
  const src = await fs.readFile(f, 'utf8');
  if (/export\s+default\b/.test(src)) throw new Error(`${f} has a default export`);
}

Try / catch

try {
  init(mod);
} catch (e) {
  if (String(e.message).includes('Cannot export `default`')) {
    console.error('Fix the remote module:', e.message);
  } else throw e;
}

Prevention

When it happens

Trigger: Adding `export default someQuery` or `export default { ... }` in a `.remote.ts` file; a bundler or refactor introducing a default export into a remote module.

Common situations: Copy-pasting service-module patterns (with default exports) into remote files; converting an old API module into a `.remote.js` file without renaming exports; code generators emitting default exports.

Related errors


AI-assisted analysis of sveltejs/kit@03f1687fe6 (2026-09-02). Data as JSON: /api/errors/b7dc4bd579f01f42. Report an issue: GitHub.