clockworklabs/SpacetimeDB · error · anyhow::Error
default export is not a Schema object
Error message
default export is not a Schema object
What it means
For v2-ABI JS modules, the default export must be a Schema object produced by the SDK's schema DSL; v2::get_hooks_from_default_export returning None means the export exists but its shape is not recognized, so the host cannot extract module hooks from it.
Solutions
- Build the default export with the current SDK's Schema/module-definition API.
- Re-scaffold from the current quickstart template and diff your entry file.
- Ensure the whole module targets one ABI version consistently.
- Match the module SDK version to the host ABI.
Example fix
// before (v2 host expects a Schema object)
export default { tables: {}, reducers: {} }; // plain object -> 'default export is not a Schema object'
// after
import { Schema } from '<current-sdk>';
export default new Schema(/* ... */); // constructed via the SDK's schema DSL Defensive patterns
Strategy: try-catch
Validate before calling
const mod = await import('./dist/module.js');
if (!mod.default || !(mod.default instanceof Schema)) {
throw new Error('default export must be a Schema object');
} Type guard
function isSchemaExport(x: unknown): x is Schema {
return x instanceof Schema;
} Try / catch
Catch module-build/publish errors; when the message mentions the default export, fail fast with a pointer to the SDK migration guide for the v2 ABI.
Prevention
- Lock the SDK version in package.json and run its codemods on major upgrades.
- Assert the default export's type in a unit test shipped with the module.
- Do not mix v1 and v2 module styles.
When it happens
Trigger: Default-exporting a plain object, arbitrary class instance, or v1-style definition where v2 expects a Schema object; an SDK major-version change altering the expected export shape; partial migration of a module to the v2 ABI.
Common situations: Upgrading the SDK without migrating the module entry point; mixing v1 and v2 patterns in one module; hand-crafted default exports.
Related errors
- must export schema as default export
- data key not found in return object
- JS worker exited before accepting
- JS worker exited before replying to
- Cannot define RLS rule on private table
AI-assisted analysis of clockworklabs/SpacetimeDB@eddf9f5014 (2026-08-20).
Data as JSON: /api/errors/b897b646667d1b64.
Report an issue: GitHub.
Appendix: source
Thrown at crates/core/src/host/v8/syscall/mod.rs:146
) -> Result<Option<HookFunctions<'scope>>, ErrorOrException<ExceptionThrown>> {
// We only set RECV_SLOT_INDEX in set_registered_hooks, which is only called in
// the v2 code path. Set it to undefined ahead of time so it's not a garbage value.
scope
.get_current_context()
.set_embedder_data(hooks::RECV_SLOT_INDEX, v8::undefined(scope).into());
if let Some(hooks) = get_registered_hooks(scope) {
return Ok(Some(hooks));
}
let default = super::str_from_ident!(default).string(scope);
let default_export = exports_obj
.get(scope, default.into())
.ok_or_else(exception_already_thrown)?;
if default_export.is_null_or_undefined() {
return Ok(None);
}
let hooks = v2::get_hooks_from_default_export(scope, default_export, exports_obj)?
.ok_or_else(|| anyhow::anyhow!("default export is not a Schema object"))?;
Ok(Some(hooks))
}
/// Process the thrown exception value into an `ExecutionError`.
pub(super) fn process_thrown_exception(
scope: &mut PinScope<'_, '_>,
hooks: &HookFunctions<'_>,
exc: Local<'_, v8::Value>,
) -> ExcResult<Option<ExecutionError>> {
match hooks.abi {
AbiVersion::V1 => Ok(None),
AbiVersion::V2 => v2::process_thrown_exception(scope, hooks, exc),
}
}
View on GitHub (pinned to eddf9f5014)