clockworklabs/SpacetimeDB · error · Error
URI is required to connect to SpacetimeDB
Error message
URI is required to connect to SpacetimeDB
What it means
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.
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
Example fix
// before
DbConnection.builder().withDatabaseName('mydb').build(); // throws: no URI
// after
DbConnection.builder().withUri(uri).withDatabaseName('mydb').build(); Defensive patterns
Strategy: validation
Validate before calling
const uri = process.env.SPACETIMEDB_URI;
if (!uri) {
throw new Error('SPACETIMEDB_URI is not set');
}
DbConnection.builder().withUri(uri).withDatabaseName('mydb').build(); Prevention
- 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()
When it happens
Trigger: 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.
Common situations: 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.
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
- Database name or address is required to connect to…
- 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/63774618d9ca3132.
Report an issue: GitHub.
Appendix: source
Thrown at crates/bindings-typescript/src/sdk/db_connection_builder.ts:265
}
/**
* Builds a new `DbConnection` with the parameters set on this `DbConnectionBuilder` and attempts to connect to the SpacetimeDB server.
*
* @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,View on GitHub (pinned to 6dee26c6ef)