clockworklabs/SpacetimeDB · critical · RangeError

unknown viewId ${id}

Error message

unknown viewId ${id}

What it means

When the host calls a (non-anonymous) view, the runtime resolves the numeric viewId against the flattened viewFns arrays of the root module and submodules. An id outside every range throws RangeError('unknown viewId <n>'), meaning the host and deployed module disagree about the view dispatch table.

Source

Thrown at crates/bindings-typescript/src/server/runtime.ts:624

      localId = id;
      dbView = this.#dbView as ReadonlyDbView<any>;
      from = makeQueryBuilder(moduleCtx.schemaType);
    } else {
      let offset = this.#consumerViewCount;
      let found = false;
      for (let i = 0; i < this.#flatSubmodules.length; i++) {
        const m = this.#flatSubmodules[i];
        if (id < offset + m.viewFns.length) {
          viewFns = m.viewFns;
          localId = id - offset;
          dbView = this.#getSubmoduleDbView(i) as ReadonlyDbView<any>;
          from = this.#getSubmoduleQueryBuilder(i);
          found = true;
          break;
        }
        offset += m.viewFns.length;
      }
      if (!found) throw new RangeError(`unknown viewId ${id}`);
    }

    const { fn, deserializeParams, serializeReturn, returnTypeBaseSize } =
      viewFns![localId!];
    const ctx: ViewCtx<any> = freeze({
      sender: new Identity(sender),
      db: dbView!,
      from: from!,
    });
    const args = deserializeParams(new BinaryReader(argsBuf));
    const ret = callUserFunction(fn, ctx, args);
    const retBuf = new BinaryWriter(returnTypeBaseSize);
    if (isRowTypedQuery(ret)) {
      const query = toSql(ret);
      ViewResultHeader.serialize(retBuf, ViewResultHeader.RawSql(query));
    } else {
      ViewResultHeader.serialize(retBuf, ViewResultHeader.RowData);
      serializeReturn(retBuf, ret);

View on GitHub (pinned to 524b4487d9)

Solutions

  1. Redeploy the module and regenerate bindings so view ids match on both sides
  2. Add views instead of reordering/removing them between deploys
  3. Align spacetimedb host, hosttools and SDK versions, and verify the deployed module hash
Defensive patterns

Strategy: validation

Prevention

When it happens

Trigger: The host dispatches a view id that no longer exists after the module was redeployed with views removed/reordered; submodule view sets differ between the build the host knows and the deployed one.

Common situations: Schema changes (dropped or reordered views) redeployed while host state or generated bindings still reference old ids; hosttools/SDK/server version skew.

Related errors


AI-assisted analysis of clockworklabs/SpacetimeDB@524b4487d9 (2026-08-16). Data as JSON: /api/errors/ba6667950c8033da. Report an issue: GitHub.