{"record":{"id":"63774618d9ca3132","repo":"clockworklabs/SpacetimeDB","slug":"uri-is-required-to-connect-to-spacetimedb","errorCode":null,"errorMessage":"URI is required to connect to SpacetimeDB","messagePattern":"URI is required to connect to SpacetimeDB","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"crates/bindings-typescript/src/sdk/db_connection_builder.ts","lineNumber":265,"sourceCode":"  }\n\n  /**\n   * Builds a new `DbConnection` with the parameters set on this `DbConnectionBuilder` and attempts to connect to the SpacetimeDB server.\n   *\n   * @returns A new `DbConnection` with the parameters set on this `DbConnectionBuilder`.\n   *\n   * @example\n   *\n   * ```ts\n   * const host = \"http://localhost:3000\";\n   * const name_or_address = \"database_name\"\n   * const auth_token = undefined;\n   * DbConnection.builder().withUri(host).withDatabaseName(name_or_address).withToken(auth_token).build();\n   * ```\n   */\n  build(): DbConnection {\n    if (!this.#uri) {\n      throw new Error('URI is required to connect to SpacetimeDB');\n    }\n\n    if (!this.#nameOrAddress) {\n      throw new Error(\n        'Database name or address is required to connect to SpacetimeDB'\n      );\n    }\n    // We could consider making this an `onConnectError` instead of throwing here.\n    // Ideally, it would be a compile time error, but I'm not sure how to accomplish that.\n    ensureMinimumVersionOrThrow(this.remoteModule.versionInfo?.cliVersion);\n\n    return this.dbConnectionCtor({\n      uri: this.#uri,\n      nameOrAddress: this.#nameOrAddress,\n      identity: this.#identity,\n      token: this.#token,\n      emitter: this.#emitter,\n      compression: this.#compression,","sourceCodeStart":247,"sourceCodeEnd":283,"githubUrl":"https://github.com/clockworklabs/SpacetimeDB/blob/6dee26c6efc2856793e12b148a59742964f5d783/crates/bindings-typescript/src/sdk/db_connection_builder.ts#L247-L283","documentation":"DbConnectionBuilder.build() requires a server URI previously set via withUri; it checks the private #uri field first. An empty field means the builder chain never set it, and build() refuses to construct a DbConnection.","triggerScenarios":"Calling build() on a builder without a prior .withUri(...), most often because the URI came from an env var that is undefined in the current environment, or because a fresh builder was built from a partial factory.","commonSituations":"Env var name mismatch between local/CI/production (e.g. SPACETIMEDB_URI unset); refactoring that drops the withUri call; config object with optional uri that is skipped silently.","solutions":["Call .withUri(uri) before .build()","Fail fast on missing config: const uri = process.env.SPACETIMEDB_URI; if (!uri) throw new Error('SPACETIMEDB_URI is not set')","Assemble the builder in one factory function so a step cannot be skipped"],"exampleFix":"// before\nDbConnection.builder().withDatabaseName('mydb').build(); // throws: no URI\n\n// after\nDbConnection.builder().withUri(uri).withDatabaseName('mydb').build();","handlingStrategy":"validation","validationCode":"const uri = process.env.SPACETIMEDB_URI;\nif (!uri) {\n  throw new Error('SPACETIMEDB_URI is not set');\n}\nDbConnection.builder().withUri(uri).withDatabaseName('mydb').build();","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Validate required connection config (uri, database name) before assembling the builder","Centralize builder assembly in one factory so withUri cannot be skipped","Fail fast at startup on missing env vars instead of deep inside build()"],"tags":["connection","configuration","builder","typescript"],"backgroundTag":"missing-required-config","analyzedSha":"6dee26c6efc2856793e12b148a59742964f5d783","analyzedAt":"2026-08-20T06:08:37.179Z","contentChangedAt":"2026-08-20T06:08:37.179Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}