{"record":{"id":"d83690c7dd80c42f","repo":"clockworklabs/SpacetimeDB","slug":"there-is-already-a-reducer-procedure-or-view-wit","errorCode":null,"errorMessage":"There is already a reducer, procedure, or view with the name '${name}'","messagePattern":"There is already a reducer, procedure, or view with the name '(.+?)'","errorType":"exception","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"crates/bindings-typescript/src/server/schema.ts","lineNumber":125,"sourceCode":"   * Maps reducer/procedure export objects to their source names.\n   * Used for resolving scheduled table targets.\n   */\n  functionExports: Map<UntypedScheduledFunctionExport, string> = new Map();\n  tableSourceNames: Map<UntypedTableSchema, string[]> = new Map();\n  httpHandlerExports: Map<HttpHandlerExport<UntypedSchemaDef>, string> =\n    new Map();\n  pendingSchedules: PendingSchedule[] = [];\n  pendingHttpRoutes: PendingHttpRoute[] = [];\n  submoduleDispatchInfos: SubmoduleDispatchInfo[] = [];\n\n  constructor(getSchemaType: (ctx: SchemaInner<S>) => S) {\n    super();\n    this.schemaType = getSchemaType(this);\n  }\n\n  defineFunction(name: string) {\n    if (this.existingFunctions.has(name)) {\n      throw new TypeError(\n        `There is already a reducer, procedure, or view with the name '${name}'`\n      );\n    }\n    this.existingFunctions.add(name);\n  }\n\n  defineHttpHandler(name: string) {\n    if (this.existingHttpHandlers.has(name)) {\n      throw new TypeError(\n        `There is already an HTTP handler with the name '${name}'`\n      );\n    }\n    this.existingHttpHandlers.add(name);\n  }\n\n  resolveSchedules() {\n    if (this.schedulesResolved) {\n      return;","sourceCodeStart":107,"sourceCodeEnd":143,"githubUrl":"https://github.com/clockworklabs/SpacetimeDB/blob/eddf9f5014579a50d4b67630e28b6e15cad9c4af/crates/bindings-typescript/src/server/schema.ts#L107-L143","documentation":"All callable module functions — reducers, procedures, and views — share one namespace per schema. `SchemaInner.defineFunction` records each export name in `existingFunctions` and throws this error on the second registration of the same name. It fires during export registration (module build/publish), naming the offending export.","triggerScenarios":"Two exported functions with the same name in one module (e.g. `transfer` reducer and `transfer` view); re-exporting a function from a submodule under a name that already exists in the entry module; a rename that leaves an old and a new export both present.","commonSituations":"Merging two feature modules that both define `init` or `tick`; copy-pasting a reducer and renaming the const but not consistently; barrel re-exports (`export * from './a'; export * from './b';`) where both files export the same name — TypeScript usually flags ambiguous star re-exports, but explicit aliases slip through.","solutions":["Rename one of the two functions named in the error message so every reducer/procedure/view export name is unique in the module.","If a submodule function collides, re-export it under an alias: `export { tick as schedulerTick } from './scheduler';`.","Run `spacetime build` locally before publish; the error is deterministic and points at the exact name.","Add a lint/CI check that collects all function export names of the entry module and fails on duplicates."],"exampleFix":"// before\nexport const transfer = spacetimedb.reducer(...);\nexport const transfer = spacetimedb.view(...); // duplicate name\n\n// after\nexport const transfer = spacetimedb.reducer(...);\nexport const transferView = spacetimedb.view(...);","handlingStrategy":"validation","validationCode":"// Dev-time: assert all function exports in the entry are uniquely named.\nconst fnNames = new Set<string>();\nfunction defineFn(name: string) {\n  if (fnNames.has(name)) throw new Error(`duplicate function export: ${name}`);\n  fnNames.add(name);\n}\n// call defineFn('transfer') wherever you create reducers/procedures/views","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Name exports after their verb+entity (`transferTokens`, `listUsers`) to avoid collisions.","Run `spacetime build` in CI so duplicate names fail the pipeline, not a deploy.","Prefer aliases at re-export sites (`export { tick as schedulerTick }`) over renames that drift."],"tags":["exports","naming","reducer","view","procedure","build-time","spacetimedb"],"backgroundTag":"duplicate-function-name","analyzedSha":"eddf9f5014579a50d4b67630e28b6e15cad9c4af","analyzedAt":"2026-08-20T06:08:37.179Z","contentChangedAt":"2026-08-20T06:08:37.179Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}