clockworklabs/SpacetimeDB · error · Error
Database name or address is required to connect to…
Error message
Database name or address is required to connect to SpacetimeDB
What it means
DbConnectionBuilder.build() requires a database name or address previously set via withDatabaseName; it checks the private #nameOrAddress field after the URI check. Missing both or just the name produces this error at build time, before any network activity.
Solutions
- Call .withDatabaseName(name) (or the address equivalent) before .build()
- Validate required connection config (uri + name) up front and throw a precise config error
- Centralize builder assembly in one connection factory
Example fix
// before
DbConnection.builder().withUri(uri).build(); // throws: no name/address
// after
DbConnection.builder().withUri(uri).withDatabaseName('mydb').build(); Defensive patterns
Strategy: validation
Validate before calling
const nameOrAddress = process.env.SPACETIMEDB_DATABASE;
if (!uri || !nameOrAddress) {
throw new Error('connection config incomplete: need both uri and database name');
}
DbConnection.builder().withUri(uri).withDatabaseName(nameOrAddress).build(); Prevention
- Set both withUri and withDatabaseName in the same factory function
- Treat empty-string config as missing, not as a valid name
- Add startup assertions for all required connection fields
When it happens
Trigger: Calling build() without .withDatabaseName(nameOrAddress): config that only sets the URI, a name read from an optional config field that is undefined, or a builder assembled by two different modules where one forgot the name.
Common situations: Assuming the database name is inferred from the URI; config split across files where the name is only wired in one path; new environment with a different database name variable left empty.
Understand the failure class
Background: "X is required", "must be set", "cannot be empty": the missing-required-config error family, from Vertex AI project/location to WeChat keys — this error's family across 18 libraries.
Related errors
- URI is required to connect to SpacetimeDB
- Brotli compression is not supported by the runtime. Please…
- Cannot nest router at
- Could not detect the language of the module. Are you in a…
- Could not find SpacetimeDB client! Did you forget to add a…
AI-assisted analysis of clockworklabs/SpacetimeDB@6dee26c6ef (2026-08-20).
Data as JSON: /api/errors/72453f17ac0c254a.
Report an issue: GitHub.
Appendix: source
Thrown at crates/bindings-typescript/src/sdk/db_connection_builder.ts:269
*
* @returns A new `DbConnection` with the parameters set on this `DbConnectionBuilder`.
*
* @example
*
* ```ts
* const host = "http://localhost:3000";
* const name_or_address = "database_name"
* const auth_token = undefined;
* DbConnection.builder().withUri(host).withDatabaseName(name_or_address).withToken(auth_token).build();
* ```
*/
build(): DbConnection {
if (!this.#uri) {
throw new Error('URI is required to connect to SpacetimeDB');
}
if (!this.#nameOrAddress) {
throw new Error(
'Database name or address is required to connect to SpacetimeDB'
);
}
// We could consider making this an `onConnectError` instead of throwing here.
// Ideally, it would be a compile time error, but I'm not sure how to accomplish that.
ensureMinimumVersionOrThrow(this.remoteModule.versionInfo?.cliVersion);
return this.dbConnectionCtor({
uri: this.#uri,
nameOrAddress: this.#nameOrAddress,
identity: this.#identity,
token: this.#token,
emitter: this.#emitter,
compression: this.#compression,
lightMode: this.#lightMode,
confirmedReads: this.#confirmedReads,
createWSFn: this.#createWSFn,
remoteModule: this.remoteModule,View on GitHub (pinned to 6dee26c6ef)