{"record":{"id":"b7dc4bd579f01f42","repo":"sveltejs/kit","slug":"cannot-export-default-from-a-remote-module-fi","errorCode":null,"errorMessage":"Cannot export `default` from a remote module (${file}) — please use named exports instead","messagePattern":"Cannot export `default` from a remote module \\((.+?)\\) — please use named exports instead","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/kit/src/exports/internal/server/remote-functions.js","lineNumber":13,"sourceCode":"/** @import { RemoteInternals } from 'types' */\n\n/** @type {RemoteInternals['type'][]} */\nconst types = ['command', 'form', 'prerender', 'query', 'query_batch', 'query_live'];\n\n/**\n * @param {Record<string, any>} module\n * @param {string} file\n * @param {string} hash\n */\nexport function init_remote_functions(module, file, hash) {\n\tif (module.default) {\n\t\tthrow new Error(\n\t\t\t`Cannot export \\`default\\` from a remote module (${file}) — please use named exports instead`\n\t\t);\n\t}\n\n\tfor (const [name, fn] of Object.entries(module)) {\n\t\tif (!types.includes(fn?.__?.type)) {\n\t\t\tthrow new Error(\n\t\t\t\t`\\`${name}\\` exported from ${file} is invalid — all exports from this file must be remote functions`\n\t\t\t);\n\t\t}\n\n\t\tfn.__.id = `${hash}/${name}`;\n\t\tfn.__.name = name;\n\t}\n}\n","sourceCodeStart":1,"sourceCodeEnd":29,"githubUrl":"https://github.com/sveltejs/kit/blob/03f1687fe612ce3d2d9131139b5b188d9cf90c64/packages/kit/src/exports/internal/server/remote-functions.js#L1-L29","documentation":"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.","triggerScenarios":"Adding `export default someQuery` or `export default { ... }` in a `.remote.ts` file; a bundler or refactor introducing a default export into a remote module.","commonSituations":"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.","solutions":["Remove the `export default` from the remote module.","Re-export each remote function by name: `export const q = query(...)`.","If a shared default object is needed, keep it in a separate non-remote module and import it into the remote file."],"exampleFix":"// before\nexport default query('getPosts', () => db.posts.all());\n// after\nexport const getPosts = query(() => db.posts.all());","handlingStrategy":"validation","validationCode":"// lint-level check before building\nconst remoteFiles = await glob('src/**/*.remote.{js,ts}');\nfor (const f of remoteFiles) {\n  const src = await fs.readFile(f, 'utf8');\n  if (/export\\s+default\\b/.test(src)) throw new Error(`${f} has a default export`);\n}","typeGuard":null,"tryCatchPattern":"try {\n  init(mod);\n} catch (e) {\n  if (String(e.message).includes('Cannot export `default`')) {\n    console.error('Fix the remote module:', e.message);\n  } else throw e;\n}","preventionTips":["Never use `export default` in *.remote.ts files.","Lint with a rule banning default exports in remote modules.","Re-export named functions only."],"tags":["remote-functions","module-exports","sveltekit"],"backgroundTag":"invalid-module-export","analyzedSha":"03f1687fe612ce3d2d9131139b5b188d9cf90c64","analyzedAt":"2026-09-02T02:01:50.504Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-09T06:17:21.866Z"}