{"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":124,"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":106,"sourceCodeEnd":142,"githubUrl":"https://github.com/clockworklabs/SpacetimeDB/blob/524b4487d949b61a07d4f39c862d1290259dfd20/crates/bindings-typescript/src/server/schema.ts#L106-L142","documentation":"SchemaInner.defineFunction guards a single shared namespace: reducers, procedures, and views may not share a name within a module (submodules are flattened into one dispatch table, so their function names also collide). Registering a second function with an existing name throws a TypeError during schema construction, before the module can build or deploy.","triggerScenarios":"Two reducers with the same name; a view named the same as a reducer or procedure (e.g. both called `leaderboard`); two submodules that each export a function with a common name like `init` or `update` and get flattened together.","commonSituations":"Copy-pasted reducers renamed at call sites but not in their definitions; merging submodules with overlapping generic names; refactoring a view into a procedure while keeping the old view.","solutions":["Rename one of the colliding functions so every reducer/procedure/view name is unique module-wide","If submodules collide, rename inside one submodule or lean on its namespace/name prefix so flattened names differ","Search the whole module (including all submodules) for the name in the error message to locate both definitions"],"exampleFix":"// before\nfunction leaderboard() {} // reducer\nfunction leaderboard() {} // view -> TypeError at schema build\n\n// after\nfunction leaderboard() {} // reducer\nfunction leaderboardView() {} // view","handlingStrategy":"validation","validationCode":"// during module build, guard the shared reducer/procedure/view namespace:\nconst seen = new Set<string>();\nfunction checkFunctionName(name: string): void {\n  if (seen.has(name)) throw new Error(`duplicate function name: ${name}`);\n  seen.add(name);\n}\n// call for every reducer, procedure, and view (including submodules)","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Treat reducer, procedure, and view names as one namespace when naming functions","Avoid generic names (init, update, tick) in submodules that get flattened together","Add a naming lint or startup check that scans all exported functions for duplicates"],"tags":["schema","naming","module-build","typescript"],"backgroundTag":"duplicate-function-name","analyzedSha":"524b4487d949b61a07d4f39c862d1290259dfd20","analyzedAt":"2026-08-16T23:58:54.611Z","schemaVersion":2},"datasetVersion":"2026-08-17T04:17:16.089Z"}